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

3 visualizaciones (últimos 30 días)
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.

Respuestas (1)

David Hill
David Hill el 6 de Mzo. de 2022
x=20:75;
X=[cosd(x).*sind(x); sind(x).*cosd(x)].*[1; 2];
  6 comentarios
David Hill
David Hill el 7 de Mzo. de 2022
Editada: David Hill el 7 de Mzo. de 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 el 7 de Mzo. de 2022
Editada: Stephen23 el 7 de Mzo. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by