Filter löschen
Filter löschen

Calculation of Phi value in matlab

8 Ansichten (letzte 30 Tage)
unknown777
unknown777 am 25 Aug. 2015
Kommentiert: unknown777 am 26 Aug. 2015
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.

Akzeptierte Antwort

maria
maria am 25 Aug. 2015
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

Weitere Antworten (1)

Image Analyst
Image Analyst am 25 Aug. 2015
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.

Kategorien

Mehr zu Statistics and Machine Learning Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by