function s=contourdata(c)
% S = CONTOURDATA(C) extracts the (x,y) data pairs describing each contour
% line and other data from the contour matrix C. The vector array structure
% S returned has the following fields:
%
% S(k).level contains the contour level height of the k-th line.
% S(k).numel contains the number of points describing the k-th line.
% S(k).isopen is True if the k-th contour is open and False if it is closed.
% S(k).xdata contains the x-axis data for the k-th line as a column vector.
% S(k).ydata contains the y-axis data for the k-th line as a column vector.
%
% For example: PLOT(S(k).xdata,S(k).ydata)) plots just the k-th contour.
if nargin<1 || ~isfloat(c) || size(c,1)~=2 || size(c,2)<4
error('CONTOURDATA:rhs',...
'Input Must be the 2-by-N Contour Matrix C.')
end
tol=1e-12;
k=1; % contour line number
col=1; % index of column containing contour level and number of points
while col
s(k).numel = c(2,col); %#ok
idx=col+1:col+c(2,col);
s(k).xdata = c(1,idx).'; %#ok
s(k).ydata = c(2,idx).'; %#ok
s(k).isopen = abs(diff(c(1,idx([1 end]))))>tol || ...
abs(diff(c(2,idx([1 end]))))>tol; %#ok
k=k+1;
col=col+c(2,col)+1;
end
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]的组合