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

3 vues (au cours des 30 derniers jours)
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.

Réponses (1)

David Hill
David Hill le 6 Mar 2022
x=20:75;
X=[cosd(x).*sind(x); sind(x).*cosd(x)].*[1; 2];
  6 commentaires
David Hill
David Hill le 7 Mar 2022
Modifié(e) : David Hill le 7 Mar 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 le 7 Mar 2022
Modifié(e) : Stephen23 le 7 Mar 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by