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!