matlab的plot基本应用说明

老外讲的挺清楚。

To create XY graphs, it is easiest to form your data into two row vectors, one for the x co-ordinates, and one for the y co-ordinates.  The command

plot(x,y)

will then create a figure with points at each y value for each matching x value.  You can control the style of any line drawn through the points by a third string argument to the plot command:

plot(x,y,style);

where style is made up from characters as follows:

q Color strings are ‘c’, ‘m’, ‘y’, ‘r’, ‘g’, ‘b’, ‘w’, and ‘k’. These correspond to cyan, magenta, yellow, red, green, blue, white, and black.

q Linestyle strings are ‘-’ for solid, ‘–’ for dashed, ‘:’ for dotted, ‘-.’ for dash-dot, and none for no line.

q The marker types are ‘+’, ‘o’, ‘*’, and ‘x’ and the filled marker types ‘s’ for square, ‘d’ for diamond, ‘^’ for up triangle, ‘v’ for down triangle, ‘>’ for right triangle, ‘<’ for left triangle, ‘p’ for pentagram, ‘h’ for hexagram, and none for no marker.

For example:

x = [ 1 2 3 4 ];

y = [ 10 15 20 25 ];

plot(x,y,’g-*’);

You can plot multiple lines by repeating the arguments:

plot(x1,y1,x2,y2,…);

or

plot(x1,y1,style1,x2,y2,style2,…);

You can give the graph a title with the

title(label);

command, where label is a character string.  Likewise you can add labels to the X and Y axes with

xlabel(label);

and

ylabel(label);

You can add a legend with

legend(label1,label2,label3,…);

http://www.phon.ucl.ac.uk/courses/spsci/matlab/lect3.html

我的小例子:

x =1:0.1:10;
y = sin(x);
plot(x,y,’m-*’);
title(‘test’);
xlabel(‘xlabel’);
ylabel(‘ylabel’);
legend(‘图例’);

image

Leave a comment

1 Comments.

  1. This is a really good read for me, Must admit that you are one of the best bloggers I ever saw.Thanks for posting this informative article.

Leave a Reply


[ Ctrl + Enter ]