Line plot in a loop

My code to plot the progress of my Newton's method algorithm vs. time currently looks like this:
f = @(x) % function
while % [not terminating condition]
% [Newton's method]
plot(t,log(abs(f(z))), '*-')
end
But of course, the '-' in the linespec doesn't do anything, since only a point, not a line, is being plotted in each iteration. How can I plot a solid line linking the last point plotted to the new one? I know I could store previous t and z and do plot([t_old t],[log(abs(f(z_old))) log(abs(f(z)))]) each time, but that is not ideal, especially since log(abs(f(z_old))) would need to be recalculated each time. There must be a smarter way, using a plot handle or line handle or some such. Can you help? Thank you.

 채택된 답변

Jan
Jan 2013년 9월 23일

0 개 추천

You could simply store log(abs(F(z_old))) and append the new value only. This would be much cheaper than the repeated calculation of the logarithm.
You can obtain the formerly drawn data from the XData and YData of the line object. Then you have to store the handle replied by plot() only and obtain the formerly coordinates by get(LineH, 'XData') etc. But the difference to storing the data directly is small.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

태그

질문:

2013년 9월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by