【问题标题】:Converting matrix data representation into meshgrid将矩阵数据表示转换为网格网格
【发布时间】:2016-08-17 08:30:51
【问题描述】:

我在 Mathematica 中用数值计算了感兴趣的函数 $f(x,y)$。为了一致性,我想使用 Matlab 进行绘图。

我以矩阵形式导出了我的函数:

 test =

-1.0000   -1.0000   -0.4864
-1.0000   -0.6000   -0.2804
-1.0000   -0.2000   -0.0462
-1.0000    0.2000   -0.0462
-1.0000    0.6000   -0.2804
-1.0000    1.0000   -0.4864
-0.6000   -1.0000   -0.2997
-0.6000   -0.6000   -0.1526
-0.6000   -0.2000    0.1118
-0.6000    0.2000    0.1118
-0.6000    0.6000   -0.1526
-0.6000    1.0000   -0.2997
-0.2000   -1.0000   -0.1809
-0.2000   -0.6000   -0.0939
-0.2000   -0.2000   -0.0046
-0.2000    0.2000   -0.0046
-0.2000    0.6000   -0.0939
-0.2000    1.0000   -0.1809
 0.2000   -1.0000   -0.1809
 0.2000   -0.6000   -0.0939
 0.2000   -0.2000   -0.0046
 0.2000    0.2000   -0.0046
 0.2000    0.6000   -0.0939
 0.2000    1.0000   -0.1809
 0.6000   -1.0000   -0.2997
 0.6000   -0.6000   -0.1526
 0.6000   -0.2000    0.1118
 0.6000    0.2000    0.1118
 0.6000    0.6000   -0.1526
 0.6000    1.0000   -0.2997
 1.0000   -1.0000   -0.4864
 1.0000   -0.6000   -0.2804
 1.0000   -0.2000   -0.0462
 1.0000    0.2000   -0.0462
 1.0000    0.6000   -0.2804
 1.0000    1.0000   -0.4864

所以test 是 36x3 矩阵,其中列是 xyf(x,y)。现在我需要绘制等高线图。

但是,它不是meshgrid的形式。有什么想法,如何快速将其转换为contour 函数可以绘制的形式?

【问题讨论】:

  • 为什么需要meshgrid 形式的?为什么不直接做contour(f)
  • 它会产生非常奇怪的结果。我确定这是不正确的,因为我在 Mathematica 中绘制了它
  • 将其绘制为y,x,f(x,y)?
  • 你能详细解释一下吗
  • contour(test(:,2),test(:,1),test(:,3))?

标签: matlab plot wolfram-mathematica


【解决方案1】:

如果你的数据是正则的(数据集与meshgrid重合,但是是向量形式),那么你可以使用reshape

xgrid=6;
ygrid=6;
contour(reshape(test(:,1),xgrid,ygrid),reshape(test(:,2),xgrid,ygrid),reshape(test(:,3),xgrid,ygrid))

另一个选项是tricontour,它也适用于不规则数据集

tri = delaunay(test(:,1),test(:,2));

figure;
tricontour(tri,test(:,1),test(:,2),test(:,3));

你可以在https://www.mathworks.com/matlabcentral/fileexchange/38858-contour-plot-for-scattered-data/content/tricontour.m找到tricontour

如果你的表面不是凸面,

那么由于delaunay 的性质,您需要从tri 中删除一些三角测量

【讨论】:

  • 好主意,但 OP 显然有一个 2d 格子网格(甚至是常规网格!),他们只是在订购点时面临后勤困难。
  • 安德拉斯·迪克,正确。 Dohyn,这不是我要找的。仅供参考
  • 在这种情况下,reshape 将起作用。检查我编辑的帖子。您可能需要交换 xgridygrid
猜你喜欢
  • 2018-07-18
  • 2012-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多