필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by