I am having difficulty with plotting to a second axis. Everything works fine until I actually try to add the 2nd Y data. I have tried various combinations of 'plotyy' and 'yyaxis right' etc. but the code below is the closest I have got to make this work. I think an added complication is that I am trying to plot 4 lines on X1,Y1 and points on X2, Y2 - but these points also relate to the same X - so in effect X1 and X2 are actually the same. My plotting code is as follows:
figure, plot(pih(:,1),'k'), hold on, plot(pih(:,2),'r'), plot(pih(:,3),'m'), plot(pih(:,4),'g'),
axesPosition = get(gca,'Position');
hNewAxes = axes('Position',axesPosition,...
and that gives the 'OK' figure above - happy with this so far, but when I try to add the data for the Y2 with this:
The result is this 'problem' figure which has overwritten.
I think that there are 2 problems - firstly, that I am not handling the 'X' axis situation properly, and the second of course that the Y2 data is not writing to the figure using the correct axis, resulting in the overwrite.
Could anyone help with these problems please?