フィルターのクリア

How to multiply two matrix in such a way that I can store individual values of the matrix

1 回表示 (過去 30 日間)
Kushagra Kirtiman
Kushagra Kirtiman 2022 年 3 月 6 日
編集済み: David Hill 2022 年 3 月 7 日
for x=20:1:75
[X]= [cos(x) sin(x); sin(x) cos(x) ]* [1; 2];
end
When I am using this code i can only use the last value which in this case comes out to be for x= 75. Is there an efficient way to code so that I can Matrix with all the values x ranging from 20 to 75.

回答 (1 件)

David Hill
David Hill 2022 年 3 月 6 日
x=20:75;
X=[cosd(x).*sind(x); sind(x).*cosd(x)].*[1; 2];
  6 件のコメント
David Hill
David Hill 2022 年 3 月 7 日
編集済み: David Hill 2022 年 3 月 7 日
Better to do a 3-D matrix so you can index into it.
a=30:75;
T= reshape([(cosd(a)).^2; (sind(a)).^2; -2*cosd(a).*sind(a); (sind(a)).^2;...
(cosd(a)).^2; 2*cosd(a).*sind(a); cosd(a).*sind(a);...
-cosd(a).*sind(a); (cosd(a)).^2-(sind(a)).^2 ],3,3,[]);
Stephen23
Stephen23 2022 年 3 月 7 日
編集済み: Stephen23 2022 年 3 月 7 日
"I want this because I am calculating coordinate transformation matrices for different winding angles so in order to calculate the siffness matrix of the lamina for different winding angles. For eg for angles 20 to 75 I want individual stifness matrcies "
Using lots of separate variables would be a very poor way to achieve that. Your proposed approach would require dynamically naming variables, which forces you into writing slow, complex, inefficient, obfuscated, code which is liable to bugs and harder to debug.
The neat, simple, and very efficient approach is to use very simple indexing, e.g. into a cell array:
So far you have no given any reason why you cannot use simpler, easier, much more efficient indexing.

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

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by