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

Click For Summary
To plot multiple iterations of a while loop on a single graph without distorting the original line, it is recommended to build a vector or array of values. For tracking convergence, the difference between the iterative result and the actual result can be stored by concatenating values into a vector, such as using "delta = [delta, loop_delta];". If generating a complete set of values, it's more effective to compile them into an array and plot all at once after the iterations are complete. This approach ensures that each iteration is represented independently on the plot.
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!
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K