Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Oct 6, 2011 #1
    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
     
  2. jcsd
  3. Oct 8, 2011 #2

    MATLABdude

    User Avatar
    Science Advisor

    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!
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook