See this documentation for Using Multiple X-Axis and Y-Axis . Something like this should do the trick:
figure ax1 = gca; hold on plot(x,y1) plot(x,y2) ax2 = axes('Position',get(ax1,'Position'),... 'XAxisLocation','top',... 'YAxisLocation','right',... 'Color','none',... 'XColor','k','YColor','k'); linkaxes([ax1 ax2],'x'); hold on plot(x,y3,'Parent',ax2);
Edit: screams, missed a hold command. Should work now. Alternatively, to remove the second X axis from above, simply add 'XTickLabel',[] to the axes command.
As an aside, you really shouldn't use arrayfun for y1=arrayfun(@(x) x^2,x); . Instead, use the .^ Operator: y1=x.^2; . This is a much better style and much faster.
Matt B.
source share