how can i put two graph into one?
Show older comments
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
1 Comment
Star Strider
on 30 Dec 2014
Answers (1)
Image Analyst
on 30 Dec 2014
0 votes
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
on 30 Dec 2014
Image Analyst
on 30 Dec 2014
I don't understand. You can't add subplots. I do see that the top (211) plot goes from 0 to 24, and I know that the lower left plot goes from 0 to 6 and the lower right one goes from 0 to 18, and 18 plus 6 is 24 but I fuzzy after that. Are you saying that you stitched together the curves in the lower left and the lower right to form new, longer curves? Okay, I can see that is probably the case, except that the "stitch" occurs at 6 hours, not 12 hours. But I don't know what to do then. Do you want the tick marks on the lower right to go from 6 to 24? Do you want the y axis for all 3 plots to go from 0 to 16? Do you want to expand/interpolate the lower left curve so that it goes over 12 hours (instead of 6) and compress the lower right curves so that they span 12 hours also (instead of 18)? If so, use interp1().
Khuram
on 31 Dec 2014
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

Categories
Find more on Image Arithmetic 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!