How to optimize this program using a for loop?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
jgg
2016-7-14
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!