顯示具有 plot 標籤的文章。 顯示所有文章
顯示具有 plot 標籤的文章。 顯示所有文章

2016年9月16日 星期五

自動儲存繪圖結果的圖形(AutoSaveFigure)

% 省略了很多MATLAB的GUI宣告(Source Code不完整)
% 在GUI裡使用了一個axes

posit = get(handles.figure1,'Position');
set(handles.figure1,'Color',[1 1 1]);  % 設背景顏色為白色
set(handles.axes1,'Position',[6 2 posit(3)-8 posit(4)-2.5]);  % Position中的數值為圖形的調整參數
for i = 3:10
    y = magic(i);
    plot([1:length(y(:))], y(:))
    drawnow;
    im = getframe(handles.figure1); % 擷取畫面
    imwrite(uint8(im.cdata),[num2str(i) '.png']);

end

% 圖形將存成3.png ~ 10.png










此外, 也可以使用script方式產生, 程式碼如下:

h1 = figure('Position', [10 10 450 300], 'Menubar''none', 'Name''AutoSave_figure');
set(h1, 'Color''white')  % 設背景顏色為白色
for i = 3:10
    y = magic(i)
    plot([1:max(y(:))], y(:));
    drawnow;
    im = getframe(h1); % 擷取畫面
    imwrite(uint8(im.cdata),[num2str(i) '.png']);
end

2015年6月13日 星期六

使用MuPAD繪製Trigonometric Function

>> mupad

plot::easy(sin(x), [PI/2,1])

plot(sin(x), [PI/2,1], #x=PI/2, #y=0.5)




f1 := plot::Function2d(sin(x), x = 0..2*PI, Color = RGB::Blue);
f2 := plot::Function2d(cos(x), x = 0..2*PI, Color = RGB::Green)

plot(f1, f2)


f1 := plot::Function2d(tan(x), x = -PI..PI, Color = RGB::Blue);


plot(f1)


f1 := plot::Function2d(cot(x), x = -PI..PI, Color = RGB::Blue);

plot(f1)


f1 := plot::Function2d(sec(x), x = -PI..PI, Color = RGB::Black);

plot(f1)

f1 := plot::Function2d(csc(x), x = -PI..PI, Color = RGB::Yellow);

plot(f1)




2015年6月4日 星期四

Plot -- Inverse Trigonometric Function

%========================================
% sin^-1(x)
%========================================
close all
figure,
x=-pi:0.1:pi;
y=sin(x);
plot(x,y,'--b')
x=[-pi/2:0.1:pi/2 pi/2];
y=sin(x);
hold on
plot(x,y,'b','LineWidth',3)
hold off
axis([-3.5 3.5 -1.5 1.5])
line( [0 0], [-1.5 1.5], 'color', 'm');
line( [-3.5 3.5], [0 0], 'color', 'm');
line( [-pi/2 -pi/2], [-1.05 0.05], 'color', 'r');
line( [pi/2 pi/2], [-0.05 1.05], 'color', 'r');
gtext('\fontname{Times New Roman}\fontsize{14}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{14}{\ity}')
gtext('(0,0)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm-{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm(-{\it\pi} /2,-1)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm({\it\pi} /2,1)')
gtext('\fontname{Times New Roman}\fontsize{14}{\itf}\rm({\itx}) = sin\itx')

x=-pi:0.1:pi;
y=sin(x);
figure, plot(x,y,'--b')
x=[-pi/2:0.1:pi/2 pi/2];
y=sin(x);
hold on
plot(x,y,'b','LineWidth',3)
x=-1:0.1:1;
y=asin(x);
plot(x,y,'g','LineWidth',3)
x=-2:0.1:2;
y=x;
plot(x,y,'--c')
hold off
axis([-2 2 -2 2])
line( [0 0], [-2 2], 'color', 'm');
line( [-2 2], [0 0], 'color', 'm');
line( [-pi/2 -pi/2], [-1.05 0.05], 'color', 'r');
line( [-1 -1], [-pi/2-0.05 0.05], 'color', 'b');
line( [pi/2 pi/2], [-0.05 1.05], 'color', 'r');
line( [1 1], [-0.05 pi/2+0.05], 'color', 'b');
line( [-1.05 0.05], [-pi/2 -pi/2], 'color', 'b');
line( [-0.05 1.05], [pi/2 pi/2], 'color', 'b');
gtext('\fontname{Times New Roman}\fontsize{12}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{12}{\ity}')
gtext('(0,0)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm-{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm(-{\it\pi} /2,-1)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm({\it\pi} /2,1)')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = sin\itx')
gtext('\fontname{Times New Roman}\fontsize{10}\rm-{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm(-1,-{\it\pi} /2)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm(1,{\it\pi} /2)')
gtext('-1')
gtext('1')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = sin^{-1}\itx')



%========================================
% cos^-1(x)
%========================================
close all
figure,
x=-pi/2:0.1:3*pi/2;
y=cos(x);
plot(x,y,'--b')
x=[0:0.1:pi pi];
y=cos(x);
hold on
plot(x,y,'b','LineWidth',3)
hold off
axis([-0.5 3.5 -1.5 1.5])
line( [0 0], [-1.5 1.5], 'color', 'm');
line( [-3.5 3.5], [0 0], 'color', 'm');
line( [-0.5 0.05], [1 1], 'color', 'r');
line( [pi pi], [-1.05 0.05], 'color', 'r');
line( [pi/2 pi/2], [-0.05 0.05], 'color', 'r');
gtext('\fontname{Times New Roman}\fontsize{12}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{12}{\ity}')
gtext('(0,0)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi}')
gtext('(0,1)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm({\it\pi},-1)')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = cos\itx')
x=-2:0.1:3*pi/2;
y=cos(x);
figure, plot(x,y,'--b')
x=[0:0.1:pi pi];
y=cos(x);
hold on
plot(x,y,'b','LineWidth',3)
x=-1:0.1:1;
y=acos(x);
plot(x,y,'g','LineWidth',3)
x=-2:0.1:4;
y=x;
plot(x,y,'--c')
hold off
axis([-2 4 -2 4])
line( [0 0], [-2 4], 'color', 'm');
line( [-2 4], [0 0], 'color', 'm');
line( [-2 0.1], [1 1], 'color', 'r');
line( [pi pi], [-1.1 0.1], 'color', 'r');
line( [pi/2 pi/2], [-0.1 0.1], 'color', 'r');
line( [-0.1 0.1], [pi/2 pi/2], 'color', 'r');
line( [-2 -0.9], [pi pi], 'color', 'b');
line( [-1 -1], [-0.1 pi+0.1], 'color', 'b');
line( [1 1], [-0.1 0.1], 'color', 'b');
gtext('\fontname{Times New Roman}\fontsize{12}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{12}{\ity}')
gtext('(0,0)')
gtext('-1')
gtext('1')
gtext('\fontname{Times New Roman}\fontsize{10}\rm({\it\pi} /2,0)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi}')
gtext('\fontname{Times New Roman}\fontsize{10}\rm({\it\pi},-1)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm(-1,{\it\pi})')
gtext('\fontname{Times New Roman}\fontsize{10}\rm(0,{\it\pi} /2)')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = cos\itx')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = cos^{-1}\itx')



%========================================
% tan^-1(x)
%========================================
close all
figure,
x=[-pi/2+0.05:0.1:pi/2];
y=tan(x);
plot(x,y,'b','LineWidth',3)
axis([-10 10 -10 10])
line( [0 0], [-10 10], 'color', 'm');
line( [-10 10], [0 0], 'color', 'm');
line( [-pi/2 -pi/2], [-10 0.2], 'color', 'r');
line( [pi/2 pi/2], [-0.2 10], 'color', 'r');
gtext('\fontname{Times New Roman}\fontsize{12}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{12}{\ity}')
gtext('(0,0)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm-{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = tan\itx')
x=[-pi/2+0.05:0.1:pi/2];
y=tan(x);
figure, plot(x,y,'b','LineWidth',3)
hold on
x=-10:0.1:10;
y=atan(x);
plot(x,y,'g','LineWidth',3)
x=-10:0.1:10;
y=x;
plot(x,y,'--c')
hold off
axis([-10 10 -10 10])
line( [0 0], [-10 10], 'color', 'm');
line( [-10 10], [0 0], 'color', 'm');
line( [-pi/2 -pi/2], [-10 0.2], 'color', 'r');
line( [pi/2 pi/2], [-0.2 10], 'color', 'r');
line( [-10 0.2], [-pi/2 -pi/2], 'color', 'b');
line( [-0.2 10], [pi/2 pi/2], 'color', 'b');
gtext('\fontname{Times New Roman}\fontsize{12}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{12}{\ity}')
gtext('(0,0)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm-{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = tan\itx')
gtext('\fontname{Times New Roman}\fontsize{10}\rm-{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = tan^{-1}\itx')




%========================================
% cot^-1(x)
%========================================
close all
figure,
x=[0.05:0.1:pi];
y=cot(x);
plot(x,y,'b','LineWidth',3)
axis([-10 10 -10 10])
line( [0 0], [-10 10], 'color', 'm');
line( [-10 10], [0 0], 'color', 'm');
line( [pi pi], [-10 0.2], 'color', 'r');
line( [pi/2 pi/2], [-0.2 0.2], 'color', 'r');
gtext('\fontname{Times New Roman}\fontsize{12}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{12}{\ity}')
gtext('(0,0)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi}')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = cot\itx')
x=[0.05:0.1:pi];
y=cot(x);
figure, plot(x,y,'b','LineWidth',3)
hold on
x=-10:0.1:-0.1;
y=acot(x)+pi;
x2=0:0.1:10;
y=[y acot(x2)];
plot([x x2],y,'g','LineWidth',3)
x=-10:0.1:10;
y=x;
plot(x,y,'--c')
hold off
axis([-10 10 -10 10])
line( [0 0], [-10 10], 'color', 'm');
line( [-10 10], [0 0], 'color', 'm');
line( [pi pi], [-10 0.2], 'color', 'r');
line( [-10 0.2], [pi pi], 'color', 'b');
gtext('\fontname{Times New Roman}\fontsize{12}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{12}{\ity}')
gtext('(0,0)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi}')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = cot\itx')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi}')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = cot^{-1}\itx')




%========================================
% sec^-1(x) ------nonunique
%========================================
close all
figure,
x=[-pi/2+0.05:0.1:pi/2-0.05];
y=sec(x);
plot(x,y,'--b')
hold on
x3 = x-3*pi;  y=sec(x3);  plot(x3,y,'--b')
x2 = x-2*pi;  y=sec(x2);  plot(x2,y,'--b')
x1 = x-pi;    y=sec(x1);  plot(x1,y,'--b')
x3 = x+3*pi;  y=sec(x3);  plot(x3,y,'--b')
x2 = x+2*pi;  y=sec(x2);  plot(x2,y,'--b')
x1 = x+pi;    y=sec(x1);  plot(x1,y,'--b')
x=[0:0.1:pi/2-0.05];
y=sec(x);
plot(x,y,'b','LineWidth',3)
x=[pi/2+0.05:0.1:pi pi];
y=sec(x);
plot(x,y,'b','LineWidth',3)
axis([-10 10 -10 10])
hold off
line( [0 0], [-10 10], 'color', 'm');
line( [-10 10], [0 0], 'color', 'm');
line( [5*pi/2 5*pi/2], [-10 10], 'color', 'r');
line( [3*pi/2 3*pi/2], [-10 10], 'color', 'r');
line( [pi/2 pi/2], [-10 10], 'color', 'r');
line( [-5*pi/2 -5*pi/2], [-10 10], 'color', 'r');
line( [-3*pi/2 -3*pi/2], [-10 10], 'color', 'r');
line( [-pi/2 -pi/2], [-10 10], 'color', 'r');
line( [-0.5 0.5], [1 1], 'color', 'r');
line( [-0.4 pi+0.4], [-1 -1], 'color', 'r');
line( [pi pi], [-1.4 0.4], 'color', 'r');
line( [2*pi 2*pi], [-0.4 1.4], 'color', 'r');
line( [-pi -pi], [-1.4 0.4], 'color', 'r');
gtext('\fontname{Times New Roman}\fontsize{12}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{12}{\ity}')
gtext('(0,0)')
gtext('1')
gtext('-1')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi}')
gtext('\fontname{Times New Roman}\fontsize{10}\rm3{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm2{\it\pi}')
gtext('\fontname{Times New Roman}\fontsize{10}\rm-{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm-{\it\pi}')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = sec\itx')
figure,
x=[-pi/2+0.05:0.1:pi/2-0.05];
y=sec(x);
plot(x,y,'--b')
hold on
x3 = x-3*pi;  y=sec(x3);  plot(x3,y,'--b')
x2 = x-2*pi;  y=sec(x2);  plot(x2,y,'--b')
x1 = x-pi;    y=sec(x1);  plot(x1,y,'--b')
x3 = x+3*pi;  y=sec(x3);  plot(x3,y,'--b')
x2 = x+2*pi;  y=sec(x2);  plot(x2,y,'--b')
x1 = x+pi;    y=sec(x1);  plot(x1,y,'--b')
x=[0:0.1:pi/2-0.05];
y=sec(x);
plot(x,y,'b','LineWidth',3)
x=[pi/2+0.05:0.1:pi pi];
y=sec(x);
plot(x,y,'b','LineWidth',3)
x=[-10:0.1:-1];
y=asec(x);
plot(x,y,'g','LineWidth',3)
x=[1:0.1:10];
y=asec(x);
plot(x,y,'g','LineWidth',3)
x=-10:0.1:10;
y=x;
plot(x,y,'--c')
hold off
line( [0 0], [-10 10], 'color', 'm');
line( [-10 10], [0 0], 'color', 'm');
line( [pi/2 pi/2], [-10 10], 'color', 'r');
line( [-0.5 0.5], [1 1], 'color', 'r');
line( [-0.4 pi+0.4], [-1 -1], 'color', 'r');
line( [pi pi], [-1.4 0.4], 'color', 'r');
line( [-10 0.4], [pi pi], 'color', 'b');
line( [-1 -1], [-0.4 pi+0.4], 'color', 'b');
line( [1 1], [-0.4 0.4], 'color', 'b');
axis([-10 10 -10 10])
gtext('\fontname{Times New Roman}\fontsize{12}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{12}{\ity}')
gtext('(0,0)')
gtext('1')
gtext('-1')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi}')
gtext('-1')
gtext('1')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi}')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = sec\itx')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = sec^{-1}\itx')



%========================================
% csc^-1(x) ------nonunique
%========================================
close all
figure,
x=[0.05:0.1:pi-0.05];
y=csc(x);
plot(x,y,'--b')
hold on
x3 = x-3*pi;  y=csc(x3);  plot(x3,y,'--b')
x2 = x-2*pi;  y=csc(x2);  plot(x2,y,'--b')
x1 = x-pi;    y=csc(x1);  plot(x1,y,'--b')
x3 = x+3*pi;  y=csc(x3);  plot(x3,y,'--b')
x2 = x+2*pi;  y=csc(x2);  plot(x2,y,'--b')
x1 = x+pi;    y=csc(x1);  plot(x1,y,'--b')
x=[0:0.1:pi/2 pi/2];
y=csc(x);
plot(x,y,'b','LineWidth',3)
x=[-pi/2:0.1:-0.05 -0.05];
y=csc(x);
plot(x,y,'b','LineWidth',3)
axis([-10 10 -10 10])
hold off
line( [0 0], [-10 10], 'color', 'm');
line( [-10 10], [0 0], 'color', 'm');
line( [5*pi/2 5*pi/2], [-10 10], 'color', 'r');
line( [3*pi/2 3*pi/2], [-10 10], 'color', 'r');
line( [pi/2 pi/2], [-10 10], 'color', 'r');
line( [-5*pi/2 -5*pi/2], [-10 10], 'color', 'r');
line( [-3*pi/2 -3*pi/2], [-10 10], 'color', 'r');
line( [-pi/2 -pi/2], [-10 10], 'color', 'r');
line( [-0.5 0.5], [1 1], 'color', 'r');
line( [-0.4 pi+0.4], [-1 -1], 'color', 'r');
line( [pi pi], [-1.4 0.4], 'color', 'r');
line( [2*pi 2*pi], [-0.4 1.4], 'color', 'r');
line( [-pi -pi], [-1.4 0.4], 'color', 'r');
gtext('\fontname{Times New Roman}\fontsize{12}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{12}{\ity}')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = csc\itx')


2015年5月28日 星期四

繪製反函數圖形(Inverse Function)

x=-3.5:0.1:3.5;
y=x.^2-1;
plot(x,y,'--b')
x=-3:0.1:-1;
y=x.^2-1;
hold on
plot(x,y,'b','LineWidth',1.5)
axis([-3.5 3.5 -1.5 10])
line( [0 0], [-1.5 10], 'color', 'm');
line( [-3.5 3.5], [0 0], 'color', 'm');
line( [-1 -1], [-0.5 0.2], 'color', 'r');
line( [-3 -3], [-0.5 9], 'color', 'r');
gtext('(0,0)')
gtext('-3')
gtext('-1')
gtext('(-3,8)')
gtext('(0,-1)')
gtext('\fontname{Times New Roman}\fontsize{14}{\itf}\rm({\itx}) = {\itx}^2-1')



x=-4:0.1:-1;
y=x.^2-1;
%subplot(1,2,2),
figure, plot(x,y,'b','LineWidth',1.5)
hold on
x=0:0.1:10;
y=-sqrt(x+1);
plot(x,y,'g','LineWidth',1.5)
x=-4:0.1:10;
y=x;
plot(x,y,'--c')
hold off
axis([-4 10 -4 10])
line( [0 0], [-4 10], 'color', 'm');
line( [-4 10], [0 0], 'color', 'm');
line( [-1 -1], [-0.5 0.2], 'color', 'r');
line( [-3 -3], [-0.5 9], 'color', 'r');
line( [-0.5 0.2], [-1 -1], 'color', 'r');
line( [-0.5 9], [-3 -3], 'color', 'r');
gtext('(0,0)')
gtext('-3')
gtext('-1')
gtext('-1')
gtext('-3')
gtext('(-3,8)')
gtext('(-1,0)')
gtext('(0,-1)')
gtext('(8,-3)')
mystr = '$f(x) = x^2-1$';
h = text('string',mystr,'interpreter','latex',...
            'fontsize',14,'units','norm','pos',[0.11 0.7]);
mystr = '$f^{-1}(x) = -\sqrt{x+1}$';
h = text('string',mystr,'interpreter','latex',...
            'fontsize',14,'units','norm','pos',[0.63 0.16]);


2014年7月17日 星期四

Legend中的字型與大小也能變更

Example:
>> plot(1:10,[1:10].*cos([1:10]),'-rs',1:10,[1:10].*sin([1:10]),'-.bo',...
1:10,[1:10].*cos([11:20]),'-g*',1:10,[11:20].*sin([11:20]),'-.k+',...
1:10,[1:10].*cos([21:30]),'--c>',1:10,[21:30].*sin([21:30]),'--yd')
>> h = legend('\fontname{標楷體}{隨機選取}\fontname{times new roman}{Lena}',...
'\fontname{標楷體}\fontsize{6}{隨機選取}\fontname{times new roman}\fontsize{10}{F16}',...
'\fontname{標楷體}{隨機選取}\fontname{times new roman}{Pepper}',...
'\fontname{標楷體}{非隨機選取}\fontname{times new roman}{Lena}',...
'\fontname{標楷體}{非隨機選取}\fontname{times new roman}{F16}',...
'\fontname{標楷體}{非隨機選取}\fontname{times new roman}\fontsize{8}{Pepper}');
>> xlabel('\fontname{times new roman}{\itp}')
>> ylabel('\fontname{times new roman}{\itPSNR}')


2013年3月25日 星期一

第五週課程----繪圖函數plot()

 一、繪圖函數plot
plot()函數命令格式如下
         格式一
                                     plot(y)


其中 y 為向量變數圖形時,若 y 屬於為實數向量x 軸將以 1、2、...、length(y),方式指定 x 軸座標,並藍色" . 點"符號(預設)分別在(1,y(1))(2,y(2))...(length(y),y(end))座標上顯示,再以實線(預設)依序將各座標連接起來若 y 屬於為複數向量x 軸將以real(y(1))real(y(2))、...real(y(end)),方式指定 x 軸座標(也就是y的實部),y 軸則為imag(y(1))imag(y(2))、...imag(y(end))(也就是y的虛部)。其中real()為取實部函數、imag()為取函數、length()可回傳向量的最大列(行)數,而end指的是向量最後一個元素

例如
          >> y=[3 2 5 7 1];
          >> plot(y)                                                             % 預設為藍色.符號與實線連接

          >> y=[3+3i 2-6i 5+i 7 1+5i];

          >> plot(y)                                                             % 預設為藍色.符號與實線連接
格式二
                                     plot(x, y, LineSpec)


其中 xy 皆為向量變數且 xy 的元素個數須相同圖形時,若 xy 皆屬於為實數向量x 軸將以 x(1)、x(2)、...、x(end) 方式指定x軸座標,並以 y(1)y(2)...y(end) 方式指定 x 軸座標線條規範語法(Line specification syntaxLineSpec)來指定繪圖曲線的樣式若 x 或 y 屬於為複數向量將忽略向量虛部部份,僅以實數部份呈現繪圖座標,並提出警告訊息(Warning: Imaginary parts of complex X and/or Y arguments ignored)

例如
          >> x=[2 4 6 7 9];
          >> y=[3 2 5 7 1];
          >> plot(x, y)                                                          % 預設為藍色.符號與實線連接
例如
          >> x=[2 4 6 7 9];
          >> y=[3+3i 2-6i 5+i 7 1+5i];
          >> plot(x, y)                                                          % 預設為藍色.符號與實線連接
          Warning: Imaginary parts of complex X and/or Y arguments ignored
格式
                                     plot(x1, y1, LineSpec1x1, y1, LineSpec2, ...)

其中 x1y1x2y2、...皆為向量變數。此時將可繪出多條曲線,分別為 x1y1 x2y2 曲線、...。各曲線皆依各線條規範語法LineSpec1LineSpec1、...指定繪圖曲線的樣式

例如
          >> x=linspace(0,2*pi,50);
          >> plot(x,sin(x),'-ro',x,cos(x),':gx')

線條規範語法(Line specification syntaxLineSpec)
        
          線條規範語法如下表所示,使用時以字串串接方式輸入,各符號的順序可以不計。

其中黃底為預設值

格式
                                     plot(x, y, LineSpec'property1', p1, 'property2'p2 ...)

其中 xy 皆為向量變數。此時僅能繪出一條曲線。曲線依線條規範語法LineSpec指定繪圖曲線的樣式。而各標記與線條的屬性 property1property2、...由p1p2、...指定屬性的英文字母大小寫不拘

         屬性如下

例如
          >> x=linspace(0,2*pi,50);
          >> plot(x,sin(x),'-rs','LineWidth',4,'markeredgecolor','b','markerfacecolor','m')
有時也可以使用set()函數重新定義標記與線條的屬性
例如
          >> x=linspace(0,2*pi,50);
          >> h = plot(x,cos(x),'-md');                                   % h為曲線的handle

接著輸入
          >> set(h, 'LineWidth',2,'Markerfacecolor','b')       % 指定調整曲線handle h的屬性

繪多條曲線也可以善加運用 hold 命令


 三、除了繪圖函數plot之外,MATLAB亦提供許多二維(2D)類型的繪圖函數。包括

1. 簡單易使用的fplot()與ezplot()
2.對數semilogx()、semilogy()、loglog()
3.累積圖形area()
4.填色函數fill()
5.火柴棒圖stem()
6.階梯圖stairs()
7.羽毛圖feather()
8.誤差條狀圖errorbar()
9.羅盤圖compass()
10.雙y軸函數plotyy()
11.繪製梯度向量場的gradient()及quiver()
12.長條圖bar()
13.橫向長條圖barh()
14.派形圖pie()
15.直方圖(histogram)hist()
16.極座標統計圖rose()
17.彗星圖comet()---俱畫的繪製圖形
18.等高線圖contour()、contourc()、contourf()
          19.極座標曲線圖polar()
使用 lookfor plot 可查出大部份的繪圖函數