How do I get the combination of cell array "wmn" and set up the preallocation of "wmn"

1 次查看(过去 30 天)
Below is my code.
In the last line of my code. Because "i" is variable, I would like to ask how to combine the wmn without using "Combine=wmn{1}+wmn{2}+wmn{3}+wmn{4}". So I can combine more term when "i" is a large number.
Also, about the second for loop, I would like to know how should I preallocate the "wmn array" with zero matrix, just as I did for the first for loop "amn=zeros(1,len)" so that I can do the calculation more efficiently.
Thank you very much!!
clc
clear
format long
E=209e+3;
q=-1;
h=15;
D=6.459478021978022e+07;
I=2.8125e+02;
a=600;b=2400;
% change the value of mn
n =7;
[T1, T2] = meshgrid(1:2:n);
mn = [T1(:), T2(:)]
syms x y
x_value=0:10:600;
y_value=0:10:2400;
[X,Y]=meshgrid(x_value,y_value)
% Fine the amn
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); % amn(i) storage the array
end
% Fine the wmn
% How do I preallocate the wmn array?
for i=1:len
m=mn(i,1);
n=mn(i,2);
wmn{i}=amn(i).*((sin(m.*pi.*X./a)).*(sin(n.*pi.*Y./b)));
end
% How do I find the combination of wmn ?
Combine=wmn{1}+wmn{2}+wmn{3}+wmn{4}

采纳的回答

KSSV
KSSV 2021-6-8
编辑:KSSV 2021-6-8
clc; clear all ;
clc
clear
format long
E=209e+3;
q=-1;
h=15;
D=6.459478021978022e+07;
I=2.8125e+02;
a=600;b=2400;
% change the value of mn
n =7;
[T1, T2] = meshgrid(1:2:n);
mn = [T1(:), T2(:)]
syms x y
x_value=0:10:600;
y_value=0:10:2400;
[X,Y]=meshgrid(x_value,y_value) ;
% Fine the amn
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); % amn(i) storage the array
end
% Fine the wmn
wmn = zeros(size(X,1),size(X,2),len) ; % preallocation
for i=1:len
m=mn(i,1);
n=mn(i,2);
wmn(:,:,i)=amn(i).*((sin(m.*pi.*X./a)).*(sin(n.*pi.*Y./b)));
end
Combine=sum(wmn(:,:,1:4),3) ; % use the function sum
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

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