How to store results of a FOR loop to plot later?
Show older comments
Hi,
I have a FOR loop which runs 10 calculations for 10 frequencies from 1 to 10Hz. This FOR loop contains another FOR loop within it which calculates the Amplitude of wave for a certain frequency. Finally I wish to plot the Amplitude vs Frequency graph. Currently my final graph only plots my Amplitude for a frequency of 10Hz. My code is shown below; Thanks
for w = 1 : 1 :10
sim('massspringdamper')
maxA = -inf;
for T=98:0.1:100
sim('massspringdamper')
ys=interp1(t,x,T);
Ys=abs(ys);
maxA=max(maxA,Ys);
end
end
figure(2);
plot(w,maxA);
xlabel('Frequency');
ylabel('Amplitude');
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements 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!