Multiple runs changing variable for plot

14 views (last 30 days)
I'd like to re-run my code each time for multiple variables. Yes, I know that I could use a for loop for this, but because my code is complex and has a long run time as is
it would be inefficient to use a for loop. So I would like to run the code for a parameter. Then, re-run the code again and draw over the current plot. However, every time I re-run the code instead of plotting the new data over the previous data I have new plots open up. I'm trying to compare how changing incident angle of a bragg reflector shifts the "filter" to the right for angles in the range of 0-60 degrees. So it's ideal that each run plots over the last run. Here is plot code so far.
%Plot the data on two seperate graphs.
figure()
subplot(2, 1, 1)
hold on
plot(range, ref_data_reflection_S)
title("Perpendicular Reflection Magnitude")
%xlabel("Incident wavelength (meters)")
ylabel("Perpendicular Reflection Magnitude")
subplot(2, 1, 2)
hold on
plot(range, ref_data_transmission_S)
title("Perpendicular Transmission Magnitude")
%xlabel("Incident wavelength (meters)")
ylabel("Perpendicular Transmission Magnitude")

Answers (1)

Star Strider
Star Strider on 25 Mar 2020
I would use savefig for each figure you want to compare later. All the data and related information as well as the figure itself will be stored in each .fig file. Load each with openfig when you want to view them.
Getting the data from them is not trivial, although it is not difficult. See the findobj function (and myriad Answers here for reference) to retrieve those data.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!