Plotting several graphs in a single one

2 views (last 30 days)
*Actually I have an optimization script. After running this script I get a graph. My question is how can I plot three graphs after running the script three times. It is obvious that I can not use from the *hold on and subplot. One idea is saving the date after each run and plotting them, but I do not know how can I save the data after each step and then use them to plot a final graph.**
  2 Comments
Walter Roberson
Walter Roberson on 30 Nov 2013
It is not obvious to me that you cannot use "hold on" or "subplot". But you have not made clear whether you need the three graphs to overlay each other or if they should appear side by side ?

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 30 Nov 2013
Put this in your script:
if exist('figureNumber', 'var')
% Increment figure number.
figureNumber = figureNumber + 1;
else
% Doesn't exist yet. Declare figureNumber.
% Start with figure #1.
figureNumber = 1;
end
figure(figureNumber);
BUT MAKE SURE YOU DON'T HAVE A CLEAR ALL ANYWHERE IN YOUR SCRIPT!
  6 Comments
ali
ali on 1 Dec 2013
I would be appreciated if you explain more when you have time.
Image Analyst
Image Analyst on 1 Dec 2013
If you're going to use functions in stead of scripts, make your variable persistent like this:
function test()
persistent figureNumber;
try
if isempty(figureNumber)
% Doesn't exist yet. Declare figureNumber.
% Start with figure #1.
figureNumber = 1;
else
% Increment figure number.
figureNumber = figureNumber + 1;
end
figure(figureNumber);
catch ME
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
fprintf(1, '%s\n', errorMessage);
uiwait(warndlg(errorMessage));
end

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D 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!