v1=linspace(0,2*pi,20); v2=sin(v1); % 建立 v1 及 v2 陣列
plot(v1, v2) % 利用 plot,輸入的變數為 x 軸接著的變數為 y 軸
v3=cos(v1); % 建立 v3 陣列
plot(v1,v2,v1,v3) % 劃二條曲線,一條代表 v1-v2 函數關係, 一條代表 v1-v3 函數關係
plot(v1,v2,v1,v2,'+') % 一樣劃二條曲線,不過第二條曲線以符號 + 標示
plot(v1,v2,v1,v2.*v3,'--') % 劃二條曲線,一條代表 v1-v2 函數關係,一條代表 v1-(v2.*v3) 函數關係且以符號'標示
xlabel('x-axis') % 加上 x 軸的說明,在二個單引號 ' 之間鍵入文字的說明
ylabel('y-axis') % 加上 y 軸的說明
title('2D plot') % 加上圖的說明
plot3(v2,v3,v1), grid % 將 v2-v1-v3 函數關係分別以x軸y軸及z軸劃,並加上格線
Matlab繪圖有幾個基本命令:
* figure: 強制生成一個新的個繪圖窗口;
* syms x y t : 聲明變量;
* fplot(函數表達式,繪圖區間);
* plot(?坐標向量,縱坐標向量,?色/?形等參數)
* ezplot(函數表達式): 簡單的fplot
* axis([xmin xmax ymin ymax ...]): 設置坐標軸顯示範圍。
使用泛函繪圖指令fplot,更為方便。比如畫某個區間的標准正態分布概率密度曲線:
fplot('normpdf(x,0,1)',[-3,3],'b-')
相應分布函數曲線:
fplot('normcdf(x,0,1)',[-3,3],'b-')
數學期望為3,方差為5的正態分布概率密度曲線:
fplot('normpdf(x,3,sqrt(5))',[-3,9],'b-')
SET Set object properties.
SET(H,'PropertyName',PropertyValue) sets the value of the
specified property for the graphics object with handle H.
H can be a vector of handles, in which case SET sets the
properties' values for all the objects.
SET(H,a) where a is a structure whose field names are object
property names, sets the properties named in each field name
with the values contained in the structure.
SET(H,pn,pv) sets the named properties specified in the cell array
of strings pn to the corresponding values in the cell array pv for
all objects specified in H. The cell array pn must be 1-by-N, but
the cell array pv can be M-by-N where M is equal to length(H) so
that each object will be updated with a different set of values
for the list of property names contained in pn.
SET(H,'PropertyName1',PropertyValue1,'PropertyName2',PropertyValue2,...)
sets multiple property values with a single statement. Note that it
is permissible to use property/value string pairs, structures, and
property/value cell array pairs in the same call to SET.
A = SET(H, 'PropertyName')
SET(H,'PropertyName')
returns or displays the possible values for the specified
property of the object with handle H. The returned array is
a cell array of possible value strings or an empty cell array
if the property does not have a finite set of possible string
values.
A = SET(H)
SET(H)
returns or displays all property names and their possible values for
the object with handle H. The return value is a structure whose
field names are the property names of H, and whose values are
cell arrays of possible property values or empty cell arrays.
The default value for an object property can be set on any of an
object's ancestors by setting the PropertyName formed by
concatenating the string 'Default', the object type, and the
property name. For example, to set the default color of text objects
to red in the current figure window:
set(gcf,'DefaultTextColor','red')
Defaults can not be set on a descendant of the object, or on the
object itself - for example, a value for 'DefaultAxesColor' can not
be set on an axes or an axes child, but can be set on a figure or on
the root.
Three strings have special meaning for PropertyValues:
'default' - use default value (from nearest ancestor)
'factory' - use factory default value
'remove' - remove default value.
See also GET, RESET, DELETE, GCF, GCA, FIGURE, AXES.
PLOT Linear plot.
PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix,
then the vector is plotted versus the rows or columns of the matrix,
whichever line up. If X is a scalar and Y is a vector, length(Y)
disconnected points are plotted.
PLOT(Y) plots the columns of Y versus their index.
If Y is complex, PLOT(Y) is equivalent to PLOT(real(Y),imag(Y)).
In all other uses of PLOT, the imaginary part is ignored.
Various line types, plot symbols and colors may be obtained with
PLOT(X,Y,S) where S is a character string made from one element
from any or all the following 3 columns:
b blue . point - solid
g green o circle : dotted
r red x x-mark -. dashdot
c cyan + plus -- dashed
m magenta * star (none) no line
y yellow s square
k black d diamond
v triangle (down)
^ triangle (up)
< triangle (left)
> triangle (right)
p pentagram
h hexagram
For example, PLOT(X,Y,'c+:') plots a cyan dotted line with a plus
at each data point; PLOT(X,Y,'bd') plots blue diamond at each data
point but does not draw any line.
PLOT(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,...) combines the plots defined by
the (X,Y,S) triples, where the X's and Y's are vectors or matrices
and the S's are strings.
For example, PLOT(X,Y,'y-',X,Y,'go') plots the data twice, with a
solid yellow line interpolating green circles at the data points.
The PLOT command, if no color is specified, makes automatic use of
the colors specified by the axes ColorOrder property. The default
ColorOrder is listed in the table above for color systems where the
default is blue for one line, and for multiple lines, to cycle
through the first six colors in the table. For monochrome systems,
PLOT cycles over the axes LineStyleOrder property.
If you do not specify a marker type, PLOT uses no marker.
If you do not specify a line style, PLOT uses a solid line.
PLOT(AX,...) plots into the axes with handle AX.
PLOT returns a column vector of handles to lineseries objects, one
handle per plotted line.
The X,Y pairs, or X,Y,S triples, can be followed by
parameter/value pairs to specify additional properties
of the lines. For example, PLOT(X,Y,'LineWidth',2,'Color',[.6 0 0])
will create a plot with a dark red line width of 2 points.
Backwards compatibility
PLOT('v6',...) creates line objects instead of lineseries
objects for compatibility with MATLAB 6.5 and earlier.
See also plottools, semilogx, semilogy, loglog, plotyy, plot3, grid,
title, xlabel, ylabel, axis, axes, hold, legend, subplot, scatter.
Reference page in Help browser
doc plot
# posted by samuel @ 1:18 AM