The extra figure calls are causing the problem. It creates a new figure, not something you want in the middle of your subplot creation. I commented them out here (just delete them in your code), and it seems to give the result you want:
num = rand(174,4);
subplot(1,2,1);
t1=datetime(2000,12,01);
t2=datetime(2015,05,01);
vr=num(:, 3);
ur=num(:, 4);
nn=t1+calmonths(0:173);
plot(nn, vr, 'r', nn,ur,'b'); xlim ([t1 t2]); datetick('x',12,'keeplimits');
subplot(1,2,2);
urbefore=num(1:80, 4);
vrbefore=num(1:80, 3);
plot(urbefore, vrbefore, '-o'); xlim ([3 11]); ylim ([1 4])
hold on
urafter=num(81:174, 4);
vrafter=num(81:174, 3);
plot(urafter, vrafter, '-o');
hold off
If you want to create a new figure (good programming practise in my opinion), call figure it before your subplot calls:
figure
subplot(2,1,1)
...
subplot(2,1,2)
...
Best Answer