Why won't my script (using for loops) loop and plot all 3 values?
8 views (last 30 days)
Show older comments
My script is supposed to plot three graphs, each using a value of k, and loop through these values. Once run, it should plot a graph and then be able to produce the other two graphs subsequently (when any key is pressed). However, it currently remains 'paused' and no graph is produced. What should I do? Here is my script:
for k = [2.9, 3.5, 3.9]
%clear figure, and the vector a
clf; clear a;
%set up vector a, a_1 = 0.5
a = zeros(1,50);
a(1) = 0.5;
for n = 2:50
a(n) = k*a(n-1)*(1-a(n-1))
end
plot(a);
title(['k=',num2str(k)]);
%pauses the loop and waits
% for any key press to continue
pause;
end
0 Comments
Answers (1)
KSSV
on 6 Apr 2017
figure
hold on
for k = [2.9, 3.5, 3.9]
%clear figure, and the vector a
%set up vector a, a_1 = 0.5
a = zeros(1,50);
a(1) = 0.5;
for n = 2:50
a(n) = k*a(n-1)*(1-a(n-1))
end
plot(a);
title(['k=',num2str(k)]);
%pauses the loop and waits
% for any key press to continue
pause;
end
USe hold on
0 Comments
See Also
Categories
Find more on Graph and Network Algorithms 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!