本文目录

%2.3矩阵数据的绘制
    %Z为一个矩阵,MATLAB将为该矩阵的每一列绘制一条线
    %在该图中,横坐标轴标以行索引矢量 1:m,m为矩阵的行数。该图为49×49的。
        clear;
        Z=peaks;
        plot(Z);
        hold on
        y=1:length(peaks);
        plot(peaks,y);
        plot(Z,y);
        hold off;
        grid on

%2.4 虚数和复数的绘制
% plot(real(Z),imag(Z));

%2.5 双Y轴绘制
    %eg1
        clear;
        t=0:pi/20:2*pi;
        y=exp(sin(t));
        plotyy(t,y,t,y,’plot’,’stem’);

    %eg2
        clear;
        t=0:900;A=1000;a=0.005;b=0.005;
        z1=A*exp(-a*t);
        z2=cos(b*t);
        [haxes,hline1,hline2]=plotyy(t,z1,t,z2,’semilogy’,’plot’);

%2.6 三维曲线图的绘制
    %plot3(x,y,z)
        clear;
        t=0:pi/50:10*pi;
        plot3(sin(t),cos(t),t);
        axis square
        grid on

%2.7 坐标轴参数的设置
    % axis 设置影响当前坐标轴(最后创建的或最后用鼠标点击选中的)对象的相关值
    % axes 按照指定的特征创建一个新的坐标轴
    % get 获取现有坐标轴的各种属性
    % set 设置现有坐标轴的各种属性
    % gca 返回当前坐标轴的句柄(即标识号ID)
    % Inf与-Inf 用于对坐标轴范围的部分指定。Inf指定最大值,-Inf指定最小值
   
    %eg1
        clear;
        %axis([-Inf 5 2 2.5]) % 设置X轴最大值为5,而最小值有MATLAB自动指定
   
    %eg2 调整坐标轴标识位置和它的显示内容
        clear;
        x=-pi:.1:pi;
        y=sin(x);
        plot(x,y);
        set(gca,’XTick’,-pi:pi/2:pi);
        set(gca,’XTickLabel’,{‘-pi’,’-pi/2′,’0′,’pi/2′,’pi’});
        xlabel(‘-pi leq Theta leq pi’);
        ylabel(‘sin(Theta)’);
        title(‘Plot of sin(Theta)’);
        text(-pi/4,sin(-pi/4),’leftarrow sin(-pidiv4)’,’HorizontalAlignment’,’left’);


    
    %eg3 坐标轴纵横比的设置
        clear;
        t=0:pi/20:2*pi;
        plot(sin(t),2*cos(t));
        axis equal tight % 另外还有square(正方形坐标图);equal 等坐标距离图;
        grid on


    
% 2.8 MATLAB的图形窗口
   
    %eg1 创建一个新的图形窗口
    clear;
    figure; %创建一个新的图形窗口
    %figure(gca);

    %eg2 单个窗口显示多个图像
    % 采用代码subplot(m,n,i)
    clear;
    t=0:pi/20:2*pi;
    [x,y]=meshgrid(t);
   
    subplot(2,2,1); %分为四格,绘制在第一格
    plot(sin(t),cos(t));
    axis equal;
    title(‘First Axis’);
   
    subplot(2,2,2);
    z=sin(x)+cos(y);
    plot(t,z);
    axis([0 2*pi -2 2]);
    title(‘Second Axis’);
   
    subplot(2,2,3);
    z=sin(x).*cos(y);
    plot(t,z);
    axis([0 2*pi -1 1]);
    title(‘Third Axis’);
   
    subplot(2,2,4);
    z=(sin(x).^2)-(cos(y).^2);
    plot(t,z);
    axis([2 2*pi -1 1]);
    title(‘Forth Axis’);
   
    %h=get(gcf,’Fourth Axis’);

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注