【问题标题】:Matlab 2D contour using X-Y coordinate dataMatlab 2D轮廓使用X-Y坐标数据
【发布时间】:2013-09-28 03:50:01
【问题描述】:

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

!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 坐标数据没有任何特定的顺序,但可以根据需要进行排列。

【问题讨论】:

    标签: matlab contour


    【解决方案1】:

    我自己也遇到过这个问题,并且从 stackoverflow 成员John D'Errico 那里找到了一个令人难以置信的解决方案,即木片。他在 Matlab Central 上名为 gridfit,package 将轻松解决您的问题。这是我自己的示例,但 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 需要一个矩形域来拟合原始数据,即使用 xnodes = -3:0.1:3; ynodes = -3:0.1:3;我拥有的原始数据可能并不总是用于矩形域(例如,二维中的环形区域)。在这种情况下,我会使用 gridfit 在环形区域内外得到错误的数据点。一个不太干净的方法可能是在感兴趣区域之外的点处屏蔽输出。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2016-06-08
      • 1970-01-01
      • 2016-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-10
      • 2014-05-30
      • 1970-01-01
      相关资源
      最近更新 更多