使用X-Y坐标数据的Matlab二维轮廓

使用X-Y坐标数据的Matlab二维轮廓,matlab,contour,Matlab,Contour,我有一组数据,如下所示: !Sr.# x-coord. y-coord potential at (x,y) 1 0.0000 1.0000 0.3508 2 0.7071 0.7071 2.0806 . .... .... .... . .... .... .... 1000 0.0000 -1.0000

我有一组数据,如下所示:

!Sr.#    x-coord.    y-coord     potential at (x,y)
  1       0.0000     1.0000      0.3508
  2       0.7071     0.7071      2.0806
  .       ....       ....        ....
  .       ....       ....        ....
 1000    0.0000     -1.0000      0.5688

我需要为上述数据生成二维等高线,其中电位值将绘制在二维等高线图上相应的(x,y)位置。我相信,为了能够使用Matlab中的contour命令绘制2D轮廓,我必须使用2D矩阵(在我的例子中,该矩阵基本上包含潜在值)。如何为这种情况创建二维矩阵?或者,是否有一种解决方法,可以完全避免二维矩阵,但仍然可以给出二维轮廓。我拥有的x-y坐标数据没有任何特定顺序,但可以根据需要进行排列。

我自己也遇到过这个问题,并从stackoverflow成员(即woodchips)那里找到了一个令人难以置信的解决方案。他在Matlab Central上的名为
gridfit,
将轻松解决您的问题。这里是我自己的例子,但是John在他难以置信的文档和演示文件中有更好的例子

% first, get some random x,y coordinates between -3 and 3
% to allow the peaks() function to look somewhat meaningful
x = rand(10,1)*6 - 3;
y = rand(10,1)*6 - 3;
% calculate the peaks function for this points
z = peaks(x,y);
% now, decide the grid we want to see, -3 to 3 at 0.1 intervals
% will be fine for this crude test
xnodes = -3:0.1:3;
ynodes = -3:0.1:3;
% now, all gridfit, notice, no sorting!  no nothing!
% just tell it the rectangular grid you want, and give it
% the raw data.  It will use linear algebra and other robust
% techniques to fit the function to the grid points
[zg,xg,yg] = gridfit(x,y,z,xnodes,ynodes);
% finally, plot the data, Viola!
contour(xg,yg,zg)

对于任意分散的数据,请查看gridfit的替代方案。

感谢gridfit的链接。这几乎就是我所需要的!!我从您的测试代码中了解到,gridfit需要一个矩形域来拟合原始数据,即使用xnodes=-3:0.1:3;ynodes=-3:0.1:3;我拥有的原始数据可能并不总是矩形区域(例如,2D中的环形区域)。在这种情况下,我将使用网格拟合在环形区域内外的假数据点结束。解决这个问题的一个不太干净的方法可能是在感兴趣区域之外的点屏蔽输出。