Trying to keep two seperate figure windows?

59 views (last 30 days)
I am writing a module that take two data sets and makes two figure windows with two different plots. I don't want to use subplot because I need to save these figures as two different graphs, not to mention it would be difficult with the code I have so far.
%First we globalize all the variables we require access to
global T Money_Saved Q_Total Hour_Step Start_Day Stop_Day Plot_Time Wall_Thickness Nodes Start_Time Stop_Time Out_Temp_All Inside_Temp
%Second we create the chart of some number of pre-selected times and
%measure the temperature through the wall as a function of position
%We need a y for every plot time
%First find out how many plot times we need
%Then we create a zero matrix to house all the numbers
%Then we create a while loop to populate it
while n<=r
%We need to get our variables assigned
%Third we set up an if statement to graph each piece of data based off of
%how many plot times we need
if m==1
xlabel('Distance Through Wall (in)')
ylabel('Temperature (Fahrenheit)')
legend('Time 1')
title('Trombe Wall Temperatures')
elseif m==2
xlabel('Distance Through Wall (in)')
ylabel('Temperature (Fahrenheit)')
legend('Time 1','Time 2')
title('Trombe Wall Temperatures')
elseif m==3
xlabel('Distance Through Wall (in)')
ylabel('Temperature (Fahrenheit)')
legend('Time 1','Time 2','Time 3')
title('Trombe Wall Temperatures')
elseif m==4
xlabel('Distance Through Wall (in)')
ylabel('Temperature (Fahrenheit)')
legend('Time 1','Time 2','Time 3','Time 4')
title('Trombe Wall Temperatures')
elseif m==5
xlabel('Distance Through Wall (in)')
ylabel('Temperature (Fahrenheit)')
legend('Time 1','Time 2','Time 3','Time 4','Time 5')
title('Trombe Wall Temperatures')
%Plotting Inside, Outside, Inside_Wall, and Outside_Wall Temperature
%Create our dependent and independent variables
%Collect some code together to save repeating it
%Independent variable is the number of hours over the study period
%Dependent variables are drived from the T matrix and from
%the Variable Assigner
%Start with the Inside Temperatures
%Inside Wall Temperature
%Inside Temperature;
%Then we do the Outside Temperatures
%Outside Wall Temperature
%Outside Temperature after being resized to for the measured time
%Then we plot the function with a dual y axis to reflect to different
%temperature extremes
xlim(AX(1),[0 Number_of_Hours])
xlim(AX(2),[0 Number_of_Hours])
xlabel('Time elapsed (hours)')
set(get(AX(1),'Ylabel'),'String', 'Outside and Outside Wall Temperature
(degrees Fahrenheit)')
set(get(AX(2),'Ylabel'),'String', 'Inside and Inside Wall Temperature
(degrees Fahrenheit)')
legend('Inside Wall Temperature','Living Space Temperature', 'Outside Wall Temperature', 'Outside Temperature')
title('Key Trombe Wall Temperatures')
gtext(sprintf('Cost Savings=$ %d',Money_Saved),sprintf('Weekly Energy Savings=',Q_Total))}
When this code runs. plotyy overwrites the old plot function. Can you help me fix this?
P.S. It might be easier and faster to simply save each figure after they are made, but I cannot find how to do that either. I would also prefer not to.

Accepted Answer

Walter Roberson
Walter Roberson on 4 Dec 2012
Before the line
add the line
fig1 = figure;
And on the same line before the plotyy() call insert
fig2 = figure;
Then at the end you can use print() or saveas() or export_fig() or whatever you prefer to save fig1 and fig2
  1 Comment
Paul on 4 Dec 2012
Thanks for the help, and sorry about the formatting, I just wasn't sure how to format it. It auto-formatted what I had :-( thanks for the help!

Sign in to comment.

More Answers (1)

Jonathan Epperl
Jonathan Epperl on 4 Dec 2012
I don't feel like reading through your post, since it isn't formatted, but I think I have a good idea what you need to know.
Explicitly create the two figures and save handles:
h1 = figure
h2 = figure
Then, make the right figure current before you call the plot or plotyy commands, as they simply plot into the "current" figure:
plot(stuff that goes into 1)
plot(stuff that goes into 2)
plot(stuff that goes into 1)
and so on and so forth. A little cleaner would be to use the handles of the created axes instead, but the above is simple and quick.
Then, to export a figure as a pdf, png or many other things, you should get this file from the FEX: Alternatively, you can use the built-in print command, which is a lot weaker.
Hope that helps, otherwise try to format your code and make it minimal, as in reduce it by getting rid of everything that's not needed to illustrate your problem.
Jonathan Epperl
Jonathan Epperl on 4 Dec 2012
@Walter: And still beat me to it ;-)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!