FOR loop with subs :: NEED HELP

8 vues (au cours des 30 derniers jours)
Ali Tawfik
Ali Tawfik le 7 Fév 2019
Commenté : Walter Roberson le 8 Fév 2019
Hi All,
I've been trying to implement a for loop to obtain different values of the following matrix (T_x_new), it's working perfect till obtaining normal T_x_new, so I just would like to add different theta for T_x_new to check different values but it's not working
Would any one mind helping me to run this code:
clear all;
syms l1 m1 n1 l2 m2 n2 l3 m3 n3 theta real;
T_x= [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_x_new=subs(T_x,{l1,m1,n1,l2,m2,n2,l3,m3,n3},{1,0,0,0,cos(theta),sin(theta),0,-sin(theta),cos(theta)});
for i=45:90;
theta=i*(pi/180);
T_x_new(:,:,i)
end

Réponse acceptée

Walter Roberson
Walter Roberson le 7 Fév 2019
for i=45:90;
theta=i*(pi/180);
subs(T_x_new)
end
This will produce 46 matrices of output, so you may wish to reconsider using 45:90 rather than (say) 45:15:90
  8 commentaires
Ali Tawfik
Ali Tawfik le 8 Fév 2019
Maybe I have to add angle(i)?, and I think I can get the result without the problem of sind and cosd..
Walter Roberson
Walter Roberson le 8 Fév 2019
angle = [0 45 30 20 90];
num = length(angle);
for i=1:num;
w(:,:,i)=double( subs(T_x_new, theta, angle(i)) );
end
Or alternately,
angle = [0 45 30 20 90];
w = double(subs(T_x_new, theta, reshape(angle, 1, 1, [])));

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by