Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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}

Réponse acceptée

KSSV
KSSV le 8 Juin 2021
Modifié(e) : KSSV le 8 Juin 2021
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 commentaires
KSSV
KSSV le 8 Juin 2021
Type error:
Replace
Combine=sum(wmn(:,:,1:4),[],3) ;
with
Combine=sum(wmn(:,:,1:4),3) ;
Edited the answer.
Mark
Mark le 8 Juin 2021
It works! Thank you very much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by