How to use the result of mn matrix at each loop step to do the calculation of amn?

1 回表示 (過去 30 日間)
Mark
Mark 2021 年 5 月 24 日
コメント済み: Mark 2021 年 5 月 25 日
There are two matrix of mn in the for loop in my command window (Please see the code below) .
The first matrix is mn= [1 1;1 3;3 1;3 3] and the second matrix is mn=[1 1;1 3;1 5;3 1;3 3;3 5;5 1;5 3;5 5].
Then I would like to plug the first matrix value and the second matrix value respectively into the the second loop function to get the two set of amn value.
Now I can only get the second set of amn value(9 elements) but how can I store the first set of amn (4 element ).
My goal is to sum different set of amn value to see the convegence behavior.
Should I store the mn matirx? or is there any suggestion way to modify my coding.
Thank you very much!!
clc
clear
format long
E=209e+3;
q=1;
h=15;
D=6.459478e+07;
a=600;b=2400;
% Control the value of mn
c=2
for f=1:c
k=[3:2:1+2*c];
[T1, T2] = meshgrid(1:2:k(f));
mn = [T1(:), T2(:)]
end
len=length(mn);
amn=zeros(1,len);
for i=1:len
m=mn(i,1);
n=mn(i,2);
amn(i)=(16*q/(m*n*D*pi^6))*(1/((m/a)^2+(n/b)^2)^2);
end
test_combine=sum(amn)

採用された回答

David Hill
David Hill 2021 年 5 月 24 日
format long
E=209e+3;
q=1;
h=15;
D=6.459478e+07;
a=600;b=2400;
% Control the value of mn
c=2;
for f=1:c
k=[3:2:1+2*c];
[T1, T2] = meshgrid(1:2:k(f));
mn{f} = [T1(:), T2(:)];
end
for f=1:c
len=length(mn{f});
amn=zeros(1,len);
for i=1:len
m=mn{f}(i,1);
n=mn{f}(i,2);
amn(i)=(16*q/(m*n*D*pi^6))*(1/((m/a)^2+(n/b)^2)^2);
end
test_combine(f)=sum(amn);
end
  1 件のコメント
Mark
Mark 2021 年 5 月 25 日
Thank you so much David Hill!
Wow! This is my first time to see how the {} operate, could you expain what is the difference between {} and ()? For the first for loop section, I originally tried to coding "mn (f)" but it indicated errors.
Really appreciate your help : )

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Control System Toolbox についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by