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

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

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by