MATLAB: Combining two stacked plots

MATLABplotting

I have two 147×1 tables. I plotted them using the stacked plot option and now have two figures. I was wondering how I can go about overlaying the plots given that they have the same x axis.
figure(1)
plot1 = stackedplot(XArray)
figure(2)
plot2 = stackedplot(YArray)
I tried
plot(plot1,plot2)
but it was invalid

Best Answer

I have no idea what ‘XArray’ and ‘YArray’ are, or how they may be related. Apparently, they have different numbers of elements, or plotting them against each other would have worked.
One possibility:
Xt = linspace(min(min(XArray),min(YArray)), max(max(XArray),max(YArray)), numel(XArray));
Yt = linspace(min(min(XArray),min(YArray)), max(max(XArray),max(YArray)), numel(YArray));
figure
plot(Xt, XArray)
hold on
plot(Yt, YArray)
hold off
grid
another possibility:
figure
plot(XArray)
hold on
plot(YArray)
hold off
grid
There may still be more possible approaches to this.
.
Related Question