Why won't my script (using for loops) loop and plot all 3 values?

8 vues (au cours des 30 derniers jours)
Charlotte Davies
Charlotte Davies le 6 Avr 2017
Réponse apportée : KSSV le 6 Avr 2017
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

Réponses (1)

KSSV
KSSV le 6 Avr 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

Catégories

En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by