*???index exceeds matrix dimensions*

i n my program i have used 'for' loop and 'if' loop at the end i am getting this comment ???index exceeds matrix dimensions after calculating 1 value, where i have to calculate 42 values
for x=1:42;
if x==1
m=Q0;
h=h0;
b1=0;
end
if x==2
m=Q0;
h=(h0+h1)/2;
b1=0;
end
if x==3
m=Q0;
h=h1;
b1=0;
end
if x==4
m=Q30;
h=h1;
b1=30;
end
if x==5
m=Q30;
h=(h1+h2)/2;
b1=30;
end
if x==6
m=Q30;
h=h2;
b1=30;
end
if x==7
m=Qn45;
h=h2;
b1=-45;
end
if x==8
m=Qn45;
h=(h2+h3)/2;
b1=-45;
end
if x==9
m=Qn45;
h=h3;
b1=-45;
end
*an so on*
%---------------- --------------------%
Ex=ex0+(h)*Kx;
Ey=ey0+(h)*Ky;
Gxy=Gxy0+(h)*Kxy;
Gxy1=Gxy/2;
GSN=[Ex,Ey,Gxy]
GSN1=[Ex;Ey;Gxy1];
%------------------------------------%
GSS=m*GSN
b=b1*(3.14/180);
C=cos(b);
S=sin(b);
%------------------------------------%
T=[C^2,S^2,(2*S*C); S^2,C^2,(-2*S*C);(-S*C),(S*C),((C^2)-(S^2))]

3 Kommentare

Jan
Jan am 22 Nov. 2011
Please post a copy of the complete error message and the line, which causes the error. Without seeing this line, even wild guessing would be too random.
Andrei Bobrov
Andrei Bobrov am 22 Nov. 2011
NOW?
%---------
for x=1:42;
...
end
Ex=ex0+(h)*Kx;
...
T=[C^2,S^2,(2*S*C); S^2,C^2,(-2*S*C);(-S*C),(S*C),((C^2)-(S^2))]
%---------------------------------------
OR
%-------------------------------
for x=1:42;
...
Ex=ex0+(h)*Kx;
...
T=[C^2,S^2,(2*S*C); S^2,C^2,(-2*S*C);(-S*C),(S*C),((C^2)-(S^2))]
end
%----------------------------------
Walter Roberson
Walter Roberson am 8 Dez. 2011
There is no such thing as an if loop.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 22 Nov. 2011

0 Stimmen

Please show clearly the line that the message is received on, with the complete traceback.
The only code that you show that could potentially be indexing, are the calls to cos() and sin(), which MATLAB could understand as indexing if you had defined variables named "cos" or "sin".
I suspect the error is occurring on a line you have not shown us.

Weitere Antworten (0)

Kategorien

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by