Calculation of Phi value in matlab

8 次查看(过去 30 天)
width=20;
length=40;
height=10;
x=1:2:20;
y=1:4:40;
z=1:1:10;
E =length/width;
alpha=atan(E);
x1= (x.*sin(alpha)) - (y .* cos (alpha));
y1= (height./2)-z;
k= y1 ./ x1;
phi1=zeros(size(k));
for ii= 1:length(k)
if k(ii)>0
phi1(ii)= atan(k(ii)); % equation 1
else
phi1(ii)= pi-atan(k(ii)); % equation 2
end
end
Error msg : ??? Subscript indices must either be real positive integers or logicals.
Sorry. I am very noob at matlab. Please help me correct with the error. I am trying to calculate the phi1 value. When k is positive it have to use the quation 1 and when k is negative it have to use the equation 2.

采纳的回答

maria
maria 2015-8-25
Try:
width=20;length=40;height=10;
x=1:2:20;
y=1:4:40;
z=1:1:10;
E =length/width;
alpha=atan(E);
x1= (x.*sin(alpha)) - (y .* cos (alpha));
y1= (height./2)-z;
k= y1 ./ x1;
[M,N]=size(k)
phi1=zeros(N);
for ii= 1:N
if k(ii)>0 phi1(ii)= atan(k(ii)); % equation 1 else phi1(ii)= pi-atan(k(ii)); % equation 2
end
end

更多回答(1 个)

Image Analyst
Image Analyst 2015-8-25
This error is very well explained by the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_fix_the_error_.22Subscript_indices_must_either_be_real_positive_integers_or_logicals..22.3F After reading that, you will know what to do.

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by