Trying to keep two seperate figure windows?

19 次查看(过去 30 天)
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
[r,~]=size(Plot_Time);
%Then we create a zero matrix to house all the numbers
y=zeros(r,Nodes);
%Then we create a while loop to populate it
n=1;
while n<=r
y(n,:)=T(:,(Plot_Time(n)-Start_Time).*Hour_Step+1);
n=n+1;
end
%We need to get our variables assigned
x=linspace(0,Wall_Thickness,length(y(1,:)));
%Third we set up an if statement to graph each piece of data based off of
%how many plot times we need
m=r;
if m==1
plot(x,y)
xlabel('Distance Through Wall (in)')
ylabel('Temperature (Fahrenheit)')
legend('Time 1')
title('Trombe Wall Temperatures')
elseif m==2
plot(x,y)
xlabel('Distance Through Wall (in)')
ylabel('Temperature (Fahrenheit)')
legend('Time 1','Time 2')
title('Trombe Wall Temperatures')
elseif m==3
plot(x,y)
xlabel('Distance Through Wall (in)')
ylabel('Temperature (Fahrenheit)')
legend('Time 1','Time 2','Time 3')
title('Trombe Wall Temperatures')
elseif m==4
plot(x,y)
xlabel('Distance Through Wall (in)')
ylabel('Temperature (Fahrenheit)')
legend('Time 1','Time 2','Time 3','Time 4')
title('Trombe Wall Temperatures')
elseif m==5
plot(x,y)
xlabel('Distance Through Wall (in)')
ylabel('Temperature (Fahrenheit)')
legend('Time 1','Time 2','Time 3','Time 4','Time 5')
title('Trombe Wall Temperatures')
end
%--------------------------------------------------------------------------
%Plotting Inside, Outside, Inside_Wall, and Outside_Wall Temperature
%Create our dependent and independent variables
%Collect some code together to save repeating it
Number_of_Hours=(Stop_Day-Start_Day)*24+Stop_Time-Start_Time;
%Independent variable is the number of hours over the study period
s=linspace(1,Number_of_Hours,Number_of_Hours*Hour_Step+1);
%Dependent variables are drived from the T matrix and from
%the Variable Assigner
%Start with the Inside Temperatures
u=ones(2,(Number_of_Hours*Hour_Step+1));
%Inside Wall Temperature
u(1,:)=T(1,:);
%Inside Temperature;
u(2,:)=u(2,:)*Inside_Temp;
%Then we do the Outside Temperatures
v=ones(2,(Number_of_Hours*Hour_Step+1));
%Outside Wall Temperature
v(1,:)=T(Nodes,:);
%Outside Temperature after being resized to for the measured time
%frame
v(2,:)=(Out_Temp_All(Start_Time*Hour_Step+1:(((Stop_Day-Start_Day)*24+Stop_Time)*Hour_Step+1),1))';
%Then we plot the function with a dual y axis to reflect to different
%temperature extremes
[AX,~,~]=plotyy(s,v,s,u);
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.

采纳的回答

Walter Roberson
Walter Roberson 2012-12-4
Before the line
m=r;
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 个评论
Paul
Paul 2012-12-4
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!

请先登录,再进行评论。

更多回答(1 个)

Jonathan Epperl
Jonathan Epperl 2012-12-4
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:
figure(h1)
plot(stuff that goes into 1)
figure(h2)
plot(stuff that goes into 2)
figure(h1)
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: http://www.mathworks.com/matlabcentral/fileexchange/23629-exportfig. 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.
  3 个评论
Paul
Paul 2012-12-4
Thanks for reformatting! and next time I'll just show the plot loops, I just didn't want there to be confusion over where I was getting my dependent and independents. Because I honestly wasn't sure were the problem might have been.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Two y-axis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by