MATLAB Answers

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

2 views (last 30 days)
WLL
WLL on 24 May 2021
Commented: WLL on 25 May 2021
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)

Accepted Answer

David Hill
David Hill on 24 May 2021
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 Comment
WLL
WLL on 25 May 2021
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 : )

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!