Line plot in a loop
Show older comments
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.
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!