MATLAB: Scaling and change the ylim for subplot

axesfigureMATLABylim;yyaxis

I plotted a figure with two y-axis with different y limit
But I would like to limit the yyaxis of the right axis so that right axis starts with the lower limit of the left plot and upper limit of the right plot?
Or if it is possible that the zero-axis of both plots matches?
I manually shifted the right plotted axis so that the zeros matches for both axis.
Thank you very much for your inputs!!

Best Answer

You should set ylim() for each axes separately. For example:
x = linspace (0, 6, 51)';
y1 = sin (x);
y2 = cos (x);
yyaxis ('left');
plot (x,y1);
ylim ([-2,2]);
yyaxis ('right');
plot (x,y2);
ylim ([-6,6]);