MATLAB: Is there a way to plot multiple graphs in one “subplot” of a stackedplot figure

MATLABstackedplot

Say I plot data with the stackedplot function. Now I want to add fits (or for simplicity: lines) to the graphs.
starttime=datetime(2018,1,1);
endtime=datetime(2018,10,1);
A=(starttime:calmonths:endtime)';
B=rand(10,3);
tableAB=table(A,B(:,1),B(:,2),B(:,3));
stackedplot(tableAB,'XVariable','A');
%add fits/lines to each graph
line([starttime endtime],[0.4 0.4],'Color','red','LineWidth',2); %for the first graph
line([starttime endtime],[0.5 0.5],'Color','green','LineWidth',2); %for the second graph
line([starttime endtime],[0.6 0.6],'Color','blue','LineWidth',2); %for the third graph
This throws the error
Error using * (line 9)
Only Cartesian axes support non-numeric data
Of course I would not expect the lines to be attached to the right plot (since there is no parameter for that [?] / I did not set the parameter).
How do I get my lines/fits (attached to the right graph) into my stackedplot figure?

Best Answer

stackedplot can plot multiple lines in the same axes. One way is to have a non-column matrix as one of your table variables:
x = randn(10,2); y = randn(10,1);
t = table(x,y);
stackedplot(t)
The first axes now contains 2 lines. Another way is to set the DisplayVariables property to a nested cellstr (or cell array of cell array of chars). Then you can plot multiple data variables in the same axes.
x = randn(10,1); y = randn(10,1);
t = table(x,y);
stackedplot(t, {{'x', 'y'}})