How to plot multiple iterations of a while loop on one plot? [MATLAB]

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 8K views
nickadams
Messages
182
Reaction score
0
If I want to plot multiple iterations of a while loop on one plot, how can I do that? Every time I use "hold on", it just distorts the original line after every iteration instead of drawing independent lines.

Please help
 
Physics news on Phys.org
I'd just build up a vector or array of values.

For instance, if you're plotting the convergence (the difference between the iterative result and the 'real' result), I'd just concatenate the value onto the vector of error values:
>> delta=[delta, loop_delta];

If, instead, you're generating an entire vector of values, I'd just build up an array, and then plot them all at the end.

Good luck!