Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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.

Antworten (1)

David Hill
David Hill am 6 Mär. 2022
x=20:75;
X=[cosd(x).*sind(x); sind(x).*cosd(x)].*[1; 2];
  6 Kommentare
David Hill
David Hill am 7 Mär. 2022
Bearbeitet: David Hill am 7 Mär. 2022
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 am 7 Mär. 2022
Bearbeitet: Stephen23 am 7 Mär. 2022
"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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by