MATLAB: Plot a graph with two axis

plot

Hi there,
I have a matrix 1440×3 and I would like to plot a graph with two axes. (x axis the same = 1440 elements)
the first two columns vary from -0.4 to 1.2, and the third one from 80 to 90.
how can I do this?
thanks a lot
Nikolas

Best Answer

You can do like this, using yyaxis:
% fake data generation:
myMatrix = [(1.2-(-0.4))*rand(20,2)+(-0.4) , sort((90-80)*rand(20,2)+80)];
% figure with two y-axis:
figure;
yyaxis left % select the left y-axis
plot(myMatrix(:,3),myMatrix(:,1)); % plot (left y-axis)
ylabel('column 1'); % label the y-axis

yyaxis right % select the right y-axis
plot(myMatrix(:,3),myMatrix(:,2)); % plot (right y-axis)
ylabel('column 2'); % label the y-axis
xlabel('column 3');
Related Question