委托代理理论ppt:matlab用plotyyA函和plotxxB生成双xy轴曲线_matlab

来源:百度文库 编辑:思考网 时间:2020/01/23 05:21:09

matlab用plotyyA函和plotxxB生成双xy轴曲线

文章来源:matlab资源网 作者:互联网

该文章讲述了matlab用plotyyA函和plotxxB生成双xy轴曲线.

matlab用plotyy(A)函和plotxx(B)生成双x/y轴曲线,具体程序如下:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%功能:多重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语句。