How do I update several graphs in one loop?
Show older comments
I'm analyzing the results of a Monte Carlo run. I have 1,000 files of seven variables, each recorded at 2,001 timesteps. The data is stored as double floats. I want to generate six plots (the seventh variable is time) with overlays of each variable vs. time. At the end, I want six plots with 1,000 curves each.
I have a loop that cycles through the 1,000 files and extracts information from each. I'd like to build these graphs in the same loop. But I can only get a plot of the data read from the current file. How do I get six different plots to be "sticky"?
4 Comments
Matthew Koebbe
on 28 Jun 2022
dpb
on 28 Jun 2022
This would be FAR more efficient to build an array of 2001x1000x6 first, then use the vectorized nature of plot() to plot each plane in turn for the six plots.
Or don't bother with the 3D array, just build each plane, plot, and go on to the next in turn.
Matthew Koebbe
on 28 Jun 2022
dpb
on 28 Jun 2022
NB: when you get to plotting that plot() is vectorized to treat columns as separate variables -- and the x variable can be a vector while the y-values are a 2D array. Just the X vector length must match the number of rows in Y.
That's where you'll get the speedup -- there was a Q? just last week where an individual was plotting some 60K points in a loop and it was taking some 10 minutes or more...<60k-lines-on-one-plot-too-slow?> I'd suggest reading it for some other ideas -- even "only" 1000 lines on a single plot probably isn't the best idea.
Answers (0)
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!