• 博客等级：
• 博客积分：0
• 博客访问：469,183
• 关注人气：272
• 获赠金笔：0支
• 赠出金笔：0支
• 荣誉徽章：

## matlab用plotyy(A)函和plotxx(B)生成双x/y轴曲线

(2010-06-10 22:39:00)

### 杂谈

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   %功能：多重x\y轴曲线的绘制 %输入：向量x1,y1,x2,y2 %输出：在同一个曲线图中，有两套x坐标轴（可以的话可以做两套y轴）   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% x1=1:10; y1=1:10; x2=1:10; y2=5:14;   hl1 = line(x1,y1,'Color','r');%第一条曲线的绘制，以默认的主x\y轴为坐标   ax1 = gca;%设置主坐标轴的颜色，用默认的位置，设定颜色 set(ax1,'XColor','r','YColor','r')   %创建第二套坐标轴，设定颜色及位置 ax2=axes('Position',get(ax1,'Position'),...            'XAxisLocation','top',...            'YAxisLocation','right',...            'Color','none',...            'XColor','k','YColor','k');   hl2 = line(x2,sin(x2),'Color','k','Parent',ax2);%第二条曲线的绘制，以ax2为坐标系   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   注意：   （1）改变x1\y1\x2\y2就可以实现plotyy()和plotxx()的功能；   （2）因为line()\axes()为low_level函数，因此都是在主窗口句柄中绘制，不会产生子窗口，所以当想多增添一条曲线时，直接再用line()函数即可，不用像plot()那样还得用hold on语句。

0