フィルターのクリア

How do I extract each value from a column matrix and subsitute in a equation?

1 回表示 (過去 30 日間)
Shiv Karpoor
Shiv Karpoor 2022 年 1 月 26 日
コメント済み: Shiv Karpoor 2022 年 1 月 26 日
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

採用された回答

Matt J
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)];
  1 件のコメント
Shiv Karpoor
Shiv Karpoor 2022 年 1 月 26 日
Hi Matt,
I have tried it yesterday, it doesn't give me the answer in the way I want it by changing the operator to elementwise.
But any ways your updated answer worked, I just tried it.
This res=@(z) reshape(z,1,1,[]); made a difference. I am getting the output the way I want it in a 3x3 matrix.
Thank you so much, I really Appreciate it.
Kind Regards,
Shiv

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by