使用X-Y坐标数据的Matlab 2D轮廓

时间:2013-02-19 22:32:57

标签: 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      0.5688

我需要为上述数据生成2D轮廓,其中电势值将绘制在2D等值线图上的相应(x,y)位置。我相信为了能够使用Matlab中的轮廓命令绘制2D轮廓,我将不得不使用2D矩阵(在我的情况下,它基本上包含潜在的值)。如何为此案例创建2D矩阵?或者是否有一种解决方法可以完全避免2D矩阵并仍然提供2D轮廓。我所拥有的x-y坐标数据没有任何特定的顺序,但如果需要可以安排。

2 个答案:

答案 0 :(得分:2)

我自己遇到过这个问题,并从stackoverflow成员John D'Errico找到了一个令人难以置信的解决方案,即木片。他在Matlab Central上的package称为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)

答案 1 :(得分:1)

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

相关问题