matlab 等高线contour
函数功能:在MATLAB中,该函数用于绘制矩阵的等高线。
语法格式:
contour(Z)
绘制矩阵Z的等高线。在这里Z表示距X-Y平面的高度。Z必须至少是一个2行2列的矩阵,且矩阵中至少包含两个不等的数值。MATLAB会根据Z中最小值和最大值自动确定等高线的条数和等高线的值。绘图区间的x、y轴范围分别为:[1:n]、[1:m]。其中[m, n] = size(Z),m表示Z的行数,n表示Z的列数。
contour(Z,n)
这里n指定了等高线的条数。
contour(Z,v)
其中v(means vector)中数据指定了要在哪些数据处绘制等高线。因此,这种调用格式将绘制出length(v)条等高线。
如果只想在高度i处画一条等高线, 使用countour(Z, [i i])。
contour(X,Y,Z)
contour(X,Y,Z,n)
contour(X,Y,Z,v)
这三种调用格式, 绘制的等高线被限定在由X、Y指定的区域内。X、Y和Z必须是同行同列的,且其中元素必须是递增的。
contour(Z)
contour(Z,n)
contour(Z,v)
contour(X,Y,Z)
contour(X,Y,Z,n)
contour(X,Y,Z,v)
contour(...,LineSpec)
contour(axes_handle,...)
[C,h] = contour(...)
contour plot displays isolines of matrix Z. Label the contour lines using .
contour(Z)draws a contour plot of matrix Z, where Zis interpreted as heights with respect to the x-yplane. Zmust be at least a 2-by-2 matrix that contains at least two different values. The number of contour lines and the values of the contour lines are chosen automatically based on the minimum and maximum values of Z. The ranges of the x- and y-axis are [1:n]and [1:m], where [m,n] = size(Z).
contour(Z,n)draws a contour plot of matrix Zwith ncontour levels.
contour(Z,v)draws a contour plot of matrix Zwith contour lines at the data values specified in the monotonically increasing vector v. The number of contour levels is equal to length(v). To draw a single contour of level i, use contour(Z,[i i]). Specifying the vector v sets the LevelListModeto manual to allow user control over contour levels. See for more information.
contour(X,Y,Z), contour(X,Y,Z,n), and contour(X,Y,Z,v)draw contour plots of Zusing Xand Yto determine the x- and y-axis limits. When Xand Yare matrices, they must be the same size as Zand must be monotonically increasing.
contour(...,LineSpec)draws the contours using the line type and color specified by . contourignores marker symbols.
contour(axes_handle,...)plots into axes axes_handleinstead of gca.
[C,h] = contour(...)returns a , C, thatcontains the x, y coordinates and contour levels for contour lines derived by the low-level function, and a handle, h, to a contourgroup object. The function uses contour matrix C to label the contour lines. is also a read-only contourgroup property that you can obtain from the returned handle.
Use contourgroupobject properties to control the contour plot appearance.
If Xor Yis irregularly spaced, contourcalculates contours using a regularly spaced contour grid, and then transforms the data to Xor Y.
---------------------------------------------------------------------------------------------------------------------
matlab获取等高线的数据
contour(X,Y,Z,v)画出Z在向量v所有值处的等高线,
如只想画出Z在i处的等高线,则调用contour(X,Y,Z, [i,i] )。
如果没有图形,可以将contour3试试看。
另外,若想获得某一等高线处的具体数据,则用[c,h]=contour(X,Y,Z,[i,i]).其中c中即包含等高线的信息,即对应Z=i处的xdata向量和ydata向量。
直接调用c就可以了,一般情况下xdata向量和ydata向量过长,显示的时候是分段显示的dim1,dim2...表示接下来一段显示的[xdata,ydata]的长度,如下:
C = [value1 xdata(1) xdata(2)... value2 xdata(1) xdata(2)...;
dim1 ydata(1) ydata(2)... dim2 ydata(1) ydata(2)...]
为方便查看,调用C'更清晰。
http://blog.sina.com.cn/s/blog_9356b06d01011udw.html
x= -5:0.05:0;
y=-x;
[X,Y] = meshgrid(x,y);
Z=-X.*Y;
surf(x,y,Z)
contour(x,y,Z)
contour(x,y,Z,[10 10])
[ii,jj]=contour(x,y,Z,[10 10])
上图,第一列,10 代表等高线为10上面的点
122代表有122对[xdata,ydata]的组合
===================
x=0:10:100;
y=500:500:10000
[xx,yy] = meshgrid(y,x);
z=[
];
[c.h] = contourf(xx,yy,x,[60:2:80, 81:1:99]);%只画60,62,64.。。。80; 81,82,83.。。。。99处的等高线
clabel(c,h);colorbar;