Subscript indices must either be real positive integers or logicals.
2 views (last 30 days)
Show older comments
James Prendergast
on 6 Jul 2017
Commented: Star Strider
on 7 Jul 2017
I got the error message after running my code (shown below). I realise that the issue is that the data I'm reading in is real numbers(decimals) and not integers. Is there any work around for matlab or way of rectifying this? The error is occuring in both the for loops. Thanks for any help provided.
f1T=transpose(f1);
f2T=transpose(f2);
i=f1T;
j=f2T;
for i=f1T
m0f1(i)= 0.5*((s1*(i+0.05))+(s1*i)*((i+0.05)-i));
mneg1f1(i)= 0.5*(s1*(i+0.05))+(s1*i)/(0.5*((i+0.05)+i))*((i+0.05)-i);
end
for j=f2T
m0f2(j)= 0.5*((s2*(j+0.1))+(s2*j)*((j+0.1)-j));
mneg1f2(j)= 0.5*(s2*(j+0.1))+(s2*j)/(0.5*((j+0.1)+j))*((j+0.1)-j);
end
m0=sum((m0f1(i))+(mof2(j)));
mneg1=sum((mneg1f1(i))+(mneg1f2(j)));
Hs=4*(SQRT(m0)); Te=mneg1/m0;
0 Comments
Accepted Answer
Star Strider
on 6 Jul 2017
Subscripts must be integers greater than zero in MATLAB.
I would do something like this:
for i=1:length(f1T)
m0f1(i)= 0.5*((s1*(f1T(i)+0.05))+(s1*f1T(i))*((f1T(i)+0.05)-f1T(i)));
mneg1f1(i)= 0.5*(s1*(f1T(i)+0.05))+(s1*f1T(i))/(0.5*((f1T(i)+0.05)+f1T(i)))*((f1T(i)+0.05)-f1T(i));
end
for j=length(f2T)
m0f2(j)= 0.5*((s2*(f2T(j)+0.1))+(s2*f2T(j))*((f2T(j)+0.1)-f2T(j)));
mneg1f2(j)= 0.5*(s2*(f2T(j)+0.1))+(s2*f2T(j))/(0.5*((f2T(j)+0.1)+f2T(j)))*((f2T(j)+0.1)-f2T(j));
end
See if that works.
10 Comments
Star Strider
on 7 Jul 2017
I understand that you are importing an Excel file (two, actually), and want to multiply the first column by the others in each row for each one. That you can do with one bsxfun call.
Example —
Rs = 5; % Row Size
Cs = 7; % Column Size
A = randi(9, Rs, Cs); % Create Data (Matrix Imported From Your Excel File)
Fv = A(:,1); % Frequencies Are First Column
Se = A(:,2:end); % ‘Signal Energy Density’ Are The Other Columns
M = bsxfun(@times, Fv, Se); % Multiply ‘Fv’ By All Other Elements In Same Row
This much I understand from your previous Comment. These should give you the 2D matrices you want. Do the same thing for each of them.
I still do not understand how you calculate ‘m0’ and ‘mneg’, and what the difference is between them.
It seems that you then want to vertically concatenate your two matrices, and then sum them column-wise, to get your (1x13139) matrix. That is easy enough to do with one sum call.
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!