How do I extract each value from a column matrix and subsitute in a equation?
2 次查看(过去 30 天)
显示 更早的评论
Hello MATLAB Community,
I have a small problem with regards to for loop.
I am trying to use the for loop to solve an equation and store all the values from that particular equation, but I am facing a problem where the loop is considering all values of a matrix to solve it.
for example : a1 = (-25 : 25); a2 = (-25 : 25); a3 = (-25 : 25);
Now I use the combvec function the find all possible combinations
comb = (combvec(a1,a2,a3)); and then I say
phi = comb(1,:);
theta = comb(2,:);
psi = comb(3,:);
Now, I need to subsitute each value of phi, theta and psi (all values of column 1 of comb matrix) into the equation:
ROT = [(cos(phi)*cos(psi))-(cos(theta)*sin(phi)*sin(psi)) -(cos(phi)*sin(psi))-(cos(theta)*cos(psi)*sin(phi)) (sin(phi)*sin(theta));...
(cos(psi)*sin(phi))+(cos(phi)*cos(theta)*sin(psi)) (cos(phi)*cos(theta)*cos(psi)-sin(phi)*sin(psi)) -(cos(phi)*sin(theta));...
(sin(theta)*sin(psi)) (cos(psi)*sin(theta)) cos(theta)];
Similarly, for the next iteration I will consider all values of column 2 of comb matrix and so on, upto the last column of the comb matrix.
Can anyone please help me with any suggestions.
Thank you in advance!!
I really appreciate your help.
Kind regards,
Shiv
0 个评论
采纳的回答
Matt J
2022-1-26
编辑:Matt J
2022-1-26
Change all of your '*' operators to elementwise operator '.*'
res=@(z) reshape(z,1,1,[]);
phi = res( comb(1,:) );
theta = res( comb(2,:) );
psi = res( comb(3,:) );
ROT = [(cos(phi).*cos(psi))-(cos(theta).*sin(phi).*sin(psi)) -(cos(phi).*sin(psi))-(cos(theta).*cos(psi).*sin(phi)) (sin(phi).*sin(theta));...
(cos(psi).*sin(phi))+(cos(phi).*cos(theta).*sin(psi)) (cos(phi).*cos(theta).*cos(psi)-sin(phi).*sin(psi)) -(cos(phi).*sin(theta));...
(sin(theta).*sin(psi)) (cos(psi).*sin(theta)) cos(theta)];
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!