How to optimize this program using a for loop?
1 view (last 30 days)
Show older comments
David Zarate Villegas
on 14 Jul 2016
Commented: David Zarate Villegas
on 14 Jul 2016
clear
close
clc
x=linspace(-5,5,1000);
y = sin(x.^2).*cos(x.^2);
fx = exp(-x.^2);
fm1 = ifft(fft(fx)/norm(fx).*y);
figure(1)
plot(abs(fm1))
fm2 = ifft(fft(fm1)/norm(fm1).*y);
figure(2)
plot(abs(fm2))
fm3 = ifft(fft(fm2)/norm(fm2).*y);
figure(3)
plot(abs(fm3))
fm4 = ifft(fft(fm3)/norm(fm3).*y);
figure(4)
plot(abs(fm4))
fm5 = ifft(fft(fm4)/norm(fm4).*y);
figure(5)
plot(abs(fm5))
fm6 = ifft(fft(fm5)/norm(fm5).*y);
figure(6)
plot(abs(fm6))
0 Comments
Accepted Answer
jgg
on 14 Jul 2016
As far as I can tell, you're just doing this:
fm1 = ifft(fft(fx)/norm(fx).*y);
figure(1)
plot(abs(fm1))
fm2 = ifft(fft(fm1)/norm(fm1).*y);
several times. So, just replacing that latter section of your code with a loop should work:
fm = ifft(fft(fx)/norm(fx).*y);
figure(1)
plot(abs(fm))
for i = 2:6
fm = ifft(fft(fm)/norm(fm).*y);
figure(i)
plot(abs(fm))
end
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!