Why won't my script (using for loops) loop and plot all 3 values?
8 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
KSSV
2017-4-6
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!