hello everyone, i want to write a code to calculate these for 121 points
for n = 1:nfreq
T1=[B(n) C(n);D(n) H(n)]
T2=[R(n) G(n);E(n) L(n)]
T=T1*inv(T2)
do you know I could do this?

 채택된 답변

Clayton Gotberg
Clayton Gotberg 2021년 4월 24일

0 개 추천

The code you've already written will calculate those values for each of 121 points.
for n = 1:nfreq
T1=[B(n) C(n);D(n) H(n)]
T2=[R(n) G(n);E(n) L(n)]
T=T1*inv(T2)
end
If you want to save the results of those calculations to use later, you can save the values in an array during the loop. For this case, with each thing you want to save being a matrix itself, I would recommend a cell array.
for n = 1:nfreq
T1=[B(n) C(n);D(n) H(n)];
T2=[R(n) G(n);E(n) L(n)];
T{n}=T1*inv(T2); % The curly braces are used to index in cell arrays
end
% example T
{{[1 2; 4 3]},{[5 3; 7 6]}}
% ^ ^
% T{1} T{2}
% 1 2 5 3
% 4 3 7 6

댓글 수: 4

Nara Lee
Nara Lee 2021년 4월 24일
thanks for your help it worked
now I want eigen value of its all cells T{n}
Clayton Gotberg
Clayton Gotberg 2021년 4월 24일
편집: Clayton Gotberg 2021년 4월 24일
I recommend you do the eigenvalue operation in the same loop, so you don't have to loop twice (I think it should save some time). You can use the eig function to get the eigenvalues (and eigenvectors if needed) and can save the results in the same way as the matrices are saved.
If you have any further questions I recommend you make another question so that all of the site can easily find it.
Nara Lee
Nara Lee 2021년 4월 24일
thank you so much
i tried this but i get error that there is no eig for cell(Undefined function 'eig' for input arguments of type 'cell'.)
ei{n}=eig(T);
Nara Lee
Nara Lee 2021년 4월 24일
then i do ei{n}=eig(T1*inv(T2))
it worked
thank you for ypur help

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2021년 4월 24일

댓글:

2021년 4월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by