How can I run multiple iterations that plot on the same graph?
조회 수: 29 (최근 30일)
이전 댓글 표시
Hello all,
I want to take the equation:
4*x+((Dl*x^2)/2)-4
I would like to run 100 iterations of this equation with Dl starting as 1 and stepping by 1 until it reaches 100.
I would also like all of the lines of this equation to be plotted on the same graph.
Any suggestions on how to do this?
Thank you!
답변 (2개)
Paul Hoffrichter
2021년 5월 26일
편집: Paul Hoffrichter
2021년 5월 26일
If you are new to Matlab programming, then you are probably used to a for-loop and you are plotting the curve in each iteration. If this is so, then all you have to do is add "hold on" to be associated with the figure.
x = -1:0.1:1; % setup x values
figure(101), clf, hold on;
ylim( [-10 55] ); % set y axis limits to keep the plot steady looking
grid on; grid minor;
for Dl = 1:100
y = 4*x + (Dl*x.^2)/2 - 4;
plot(x,y);
title( ['Iteration #: ' num2str(Dl) ] );
pause(0.1); % add this to see the effect of each iteration
end
figure(101), hold off;
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!