MATLAB: How to plot graphs with unequal axes in the same plot in MATLAB 7.7 (R2008b)

differentMATLABplotxxplotyy

I would like to plot graphs with unequal axes in the same plot.

Best Answer

Here is an example of two graphs with unequal X-axes and unequal spacing, in the same figure.
x1 = [0:.1:40];
y1 = 4.*cos(x1)./(x1+2);
x2 = [1:.2:20];
y2 = x2.^2./x2.^3;
hl1 = line(x1,y1,'Color','r');
ax1 = gca;
ax2 = axes('Position',get(ax1,'Position'),...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none',...
'XColor','k','YColor','k');
hl2 = line(x2,y2,'Color','k','Parent',ax2);
set(ax1,'XColor','r','YColor','r')
One of these File Exchange Submissions may also be of interest:
Note that The MathWorks does not guarantee or warrant the use or content of these submissions. Any questions, issues, or complaints should be directed to the contributing author.