1 view (last 30 days)

Hi,

I have been trying the following commands, but I could not, and got that error, (I got that error, Subscript indices must either be real positive integers or logicals.),

for i=[90,30,-30]

theta(i)=i*pi/180

end

& also, when type length of (i) it equals =-30, how ?, and I have 3 variables ?

actually, I hope to have 3 variables (one at i =90, and another =30, and so on ]

So please could you tell me how could I do this ?

Thanks,

Walter Roberson
on 12 Jul 2019

Walter Roberson
on 13 Jul 2019

thetaDegrees = [90,30,-30];

for K = 1 : 3

thetaRadians = thetaDegrees(K) * sym(pi) / 180;

T=[l1^2 m1^2 n1^2 2*m1*n1 2*l1*n1 2*l1*m1;

l2^2 m2^2 n2^2 2*m2*n2 2*l2*n2 2*l2*m2;

l3^2 m3^2 n3^2 2*m3*n3 2*l3*n3 2*l3*m3;

l2*l3 m2*m3 n2*n3 m2*n3+n2*m3 l2*n3+n2*l3 l2*m3+m2*l3;

l1*l3 m1*m3 n1*n3 m1*n3+n1*m3 l1*n3+n1*l3 l1*m3+m1*l3;

l1*l2 m1*m2 n1*n2 m1*n2+n1*m2 l1*n2+n1*l2 l1*m2+m1*l2];

T_n{K} = subs(T,{l1,m1,n1,l2,m2,n2,l3,m3,n3},{cos(theta_rad),sin(theta_rad),aij_z(1,3),...

-sin(theta_rad),cos(theta_rad),aij_z(2,3),...

aij_z(3,1),aij_z(3,2),aij_z(3,3)});

end

T_n{2}

T_n{3}

Geoff Hayes
on 12 Jul 2019

Edited: Geoff Hayes
on 12 Jul 2019

Ali - your for loop is iterating over the array [90, 30, -30] so your i is becoming each of these values. That is fine (for the equation) but fails when you use i as an index into your array and i is -30 (and so the error message makes sense). You can avoid the loop and just do

thetaDegrees = [90,30,-30];

thetaRadians = thetaDegrees * pi / 180;

Geoff Hayes
on 12 Jul 2019

Ali - what other commands should be added so that you need a for loop? Can't you just extend the above as

anglesDegrees = [-90 -60 -30 0 30 60 90];

degreeToRadianMap = containers.Map(anglesDegrees, anglesDegrees * pi / 180);

?

Geoff Hayes
on 12 Jul 2019

Opportunities for recent engineering grads.

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

Start Hunting!
## 0 Comments

Sign in to comment.