How to Preallocate this loop?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
suriyaprasanth s
il 4 Mar 2021
Modificato: KALYAN ACHARJYA
il 4 Mar 2021
%clear all
tic
ncut=60;
alpha=3;
for nloop=1:ncut
zx=(-3+(nloop/10));
xaxis(nloop)=zx;
for ploop=1:ncut
zy=(-3+(ploop/10));
yaxis(ploop)=zy;
z=zx+(1j*zy);
term1=(1/pi*(1+exp(-2*abs(z-alpha)^2)));
term2=(exp(-2*abs(z-alpha)^2));
term3=(exp(-2*abs(z+alpha)^2));
term4=(exp(-2*((abs(z)^2)+z*conj(alpha)-alpha*conj(z))));
term5=(exp(-2*((abs(z)^2)-z*conj(alpha)+alpha*conj(z))));
term6=(term2+term3+term4+term5)*term1;
wig(nloop,ploop)=real(term6);
end
end
surf(xaxis,yaxis,wig)
timelapsed = toc
how to preallocate the for loop?
0 Commenti
Risposta accettata
KALYAN ACHARJYA
il 4 Mar 2021
Modificato: KALYAN ACHARJYA
il 4 Mar 2021
xaxis=zeros(1,ncut);
yaxis=zeros(1,ncut);
wig=zeros(ncut,ncut);
More: Avoid using xaxis and yaxis as variable names, there may be possibility of conflicts with Matlab inbuilt function.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!