Try a function from the file exchange
Or adapt this demo to your needs (yyaxis requires r2016a or later)
Setting up two y axes is trivial. Three y axes, not so trivial. You'll need to set up a plot with and right and left y axes (using yyaxis) and then you'll need to overlay invisible axes on top of the original ones, perfectly placed, and perfectly scaled so the vertical and horizontal ticks align. Finally, add some space to the right of the y tick labels so they are horizontally offset.
Here's a demo that you can adapt to your needs. The critical steps are setting the axis ticks and making sure the spacing is the same between axes. I use the grid feature for both axes to ensure that they are overlayed property (otherwise you'll see double grids).
x = 0:.1:3;
y1 = exp(x);
y2 = log(x);
y3 = x.^2;
figure
ax1 = axes;
yyaxis left
plot(x,y1)
pause(0.1)
ax1.XTickMode = 'manual';
ax1.YTickMode = 'manual';
ax1.YLim = [min(ax1.YTick), max(ax1.YTick)];
ax1.XLimMode = 'manual';
grid(ax1,'on')
ytick = ax1.YTick;
yyaxis right
plot(x,y2)
ax2 = axes('position', ax1.Position);
plot(ax2,x,y3, 'k')
pause(0.1)
ax2.Color = 'none';
grid(ax2, 'on')
ax2.XLim = ax1.XLim;
ax2.XTick = ax1.XTick;
ax2.YLimMode = 'manual';
yl = ax2.YLim;
ax2.YTick = linspace(yl(1), yl(2), length(ytick));
ax2.YTickLabel = strcat(ax2.YTickLabel, {' '});
Changes needed to create the double y-axis on the right side instead of the left side
- Calculate ytick = ax1.YTick after plotting on the right axis.
- After creating ax2, set the y axis location to the right side using ax2.YAxisLocation = 'right';
- Pad the left side of the ax2 y-axis ytick lables instead of the right side by changing: ax2.YTickLabel = strcat({' '},ax2.YTickLabel);
For matlab releases prior to 2016a, use plotyy() instead
The code above has been adapted to plotyy().
x = 0:.1:3;
y1 = exp(x);
y2 = log(x);
y3 = x.^2;
figure
yyh = plotyy(x,y1,x,y2);
yyh(1).XTickMode = 'manual';
yyh(1).YTickMode = 'manual';
yyh(1).YLim = [min(yyh(1).YTick), max(yyh(1).YTick)];
yyh(1).XLimMode = 'manual';
grid(yyh(1),'on')
ytick = yyh(1).YTick;
ax2 = axes('position', yyh(1).Position);
plot(ax2,x,y3, 'k')
pause(0.1)
ax2.Color = 'none';
grid(ax2, 'on')
ax2.XLim = yyh(1).XLim;
ax2.XTick = yyh(1).XTick;
ax2.YLimMode = 'manual';
yl = ax2.YLim;
ax2.YTick = linspace(yl(1), yl(2), length(ytick));
ax2.YTickLabel = strcat(ax2.YTickLabel, {' '});