how can i put two graph into one?

1 view (last 30 days)
Khuram
Khuram on 30 Dec 2014
Commented: Image Analyst on 1 Jan 2015
hello everyone; I am trying to put the bottom two graph into one but the first graph is should be until 6 and then the next one start, but the first one expand to 12, can someone help me please, thanks
here's my code and graph
clc; clear
k=0.5; rho=2023;cv=1825; aLf=k/(rho*cv);
L=0.25;nx=5; nxp=nx+1; dx=L/nx;
td=6*3600; %day time
tn=18*3600; %night time
Tt=td+tn;nt=60;ntp=nt+1;nTp=2*ntp;
dtd=td/nt;
dtn=tn/nt;
Tsd=20;Tsn=0; Ti=10;
tday=linspace(0,td,ntp); tnight=linspace(0,tn,ntp);
y=linspace(0,Tt,nTp);
T1=zeros(1,ntp);T2=zeros(1,ntp);
T1(1)=Ti;Tni=zeros(1,nxp); Tnii=zeros(1,nxp);
for i=1:nxp
depth(i)=i*dx;
for j=1:ntp
time(j)= j*dtd;
Tx=Tsd+((Ti-Tsd)*(erf(depth(i)/(2*sqrt(aLf*(time(j)))))));
T1(j)=Tx;
T1M(i,:) = T1;
end
Tni(i)=Tx;
for k=1:ntp
time2(k)= k*dtn;
Ty=Tsn+((Tni(i)-Tsn)*(erf(depth(i)/(2*sqrt(aLf*(time2(k)))))));
T2(k)=Ty;
T2M(i,:) = T2;
end
T=[T1M T2M];
%plots
subplot(223);
plot(tday/3600,T1,'linewidth',2); hold on; xlabel('time (hours)'); ylabel('Temperature(Tx)');grid on
xlim([0 7])
subplot(224);
plot(tnight/3600,T2,'linewidth',2); hold on; xlabel('time (t)'); ylabel('Temperature(Tx)');grid on
xlim([0 19])
subplot(211);
plot(y/3600,T,'linewidth',2); hold on; xlabel('time (hours)'); ylabel('Temperature(Tx)');grid on
xlim([0 25])
end
can someone help me please, thanks

Answers (1)

Image Analyst
Image Analyst on 30 Dec 2014
I have no idea what this means: "the first graph is should be until 6 and then the next one start, but the first one expand to 12," WHAT should be until 6 and WHAT's expanding until 12? Are you talking about the x or y axis and in which of the 3 subplots?
Why don't you just not call subplot the last time and call "hold on" if you want things plotted on the same plot/graph/axis?
  4 Comments
Khuram
Khuram on 31 Dec 2014
i want the subplot(211) give me exactly same as the 2 lower plots, so the first curve(in subplot(211)) should finish at 6 and then the next curve start from 6 to 24.
Image Analyst
Image Analyst on 1 Jan 2015
It's kind of confusing - all those T's. And the last T you plot in the top plot is actually 6 curves already while the other two are just single curves. But I did my best and this is what I got.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
% clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
k=0.5;
rho=2023;
cv=1825;
aLf=k/(rho*cv);
L=0.25;
nx=5;
nxp=nx+1;
dx=L/nx;
td=6*3600; %day time
tn=18*3600; %night time
Tt=td+tn;
nt=60;
ntp=nt+1;
nTp=2*ntp;
dtd=td/nt;
dtn=tn/nt;
Tsd=20;
Tsn=0;
Ti=10;
tday=linspace(0,td,ntp);
tnight=linspace(0,tn,ntp);
y=linspace(0,Tt,nTp);
T1=zeros(1,ntp);
T2=zeros(1,ntp);
T1(1)=Ti;
Tni=zeros(1,nxp);
Tnii=zeros(1,nxp);
for i=1:nxp
depth(i)=i*dx;
for j=1:ntp
time1(j)= j*dtd;
Tx=Tsd+((Ti-Tsd)*(erf(depth(i)/(2*sqrt(aLf*(time1(j)))))));
T1(j)=Tx;
T1M(i,:) = T1;
end
Tni(i)=Tx;
for k=1:ntp
time2(k)= k*dtn;
Ty=Tsn+((Tni(i)-Tsn)*(erf(depth(i)/(2*sqrt(aLf*(time2(k)))))));
T2(k)=Ty;
T2M(i,:) = T2;
end
T=[T1M T2M];
% Plots
% Get random color
thisColor = rand(1, 3)
% Plot lower left plot.
subplot(223);
x1 = tday/3600;
plot(x1, T1, 'linewidth', 2, 'Color', thisColor);
if i == 1
xlabel('Time (hours)', 'FontSize', fontSize);
ylabel('Temperature (Tx)', 'FontSize', fontSize);
grid on
xlim([0 7]);
hold on;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
end
% Plot lower right plot.
subplot(224);
x2 = tnight/3600;
plot(x2, T2, 'linewidth', 2, 'Color', thisColor);
if i == 1
hold on;
xlabel('Time (hours)', 'FontSize', fontSize);
ylabel('Temperature (Tx)', 'FontSize', fontSize);
grid on
xlim([0 19]);
end
% Plot upper/top plot.
subplot(211);
x3 = [x1, x2+x1(end)];
plot(x3, T(i,:), 'linewidth', 2, 'Color', thisColor);
if i == 1
hold on;
xlabel('Time (hours)', 'FontSize', fontSize);
ylabel('Temperature (Tx)', 'FontSize', fontSize);
grid on
xlim([0 25]);
end
end

Sign in to comment.

Categories

Find more on Line 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!