*???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

Jan
Jan 2011년 11월 22일
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 2011년 11월 22일
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 2011년 12월 8일
There is no such thing as an if loop.

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2011년 11월 22일

0 개 추천

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.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by