Hello,
I have written a code which calculates certain parameters and plots several subplots in a figure as follows:
figure('name','my_title');h1=subplot(2,2,1);plot (x1,y1);h1=subplot(2,2,2);plot(x2,y2);h1=subplot(2,2,3);plot(x3,y3);h1=subplot(2,2,4);plot(x4,y4);
Now I have to run the same code multile times for differnet data sets. I would like to keep the existing subplots (from lets say data set 1) and plot the new subplots (from lets say data set 2) on top of the existing subplots for comparison. But everytime I try to do it, its erasing the existing subplots and only plotting the current data set.
I tried to use findobj to check whether the figure exists and if so then use it as follows:
fOp.figName='my_title';hf=findobj('Type','figure');if ~isempty(hf) figure(hf);hold all;else hf = figure('Name',fOp.figName); hold all;endh1=subplot(2,2,1);hold all;plot (x1,y1);h1=subplot(2,2,2);hold all;plot(x2,y2);h1=subplot(2,2,3);hold all;plot(x3,y3);h1=subplot(2,2,4);hold all;plot(x4,y4);
While it keeps the figure 1 open for the multiple runs, but it still erases the previous subplots inside the figure 1. I think I have to use 'Children' function in some way but not sure how. Any help would be much appreciated. Thank you.
Best Answer