How to Preallocate this loop?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
suriyaprasanth s
am 4 Mär. 2021
Bearbeitet: KALYAN ACHARJYA
am 4 Mär. 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 Kommentare
Akzeptierte Antwort
KALYAN ACHARJYA
am 4 Mär. 2021
Bearbeitet: KALYAN ACHARJYA
am 4 Mär. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!