在 Matlab 中绘制类似于使用 Gnuplot 获得的曲面图?
更新:
链接到我的测试数据集
我有一些这样的数据:
10.0 11.0 0.5
10.0 12.0 0.5
10.0 14.5 0.5
10.0 16.0 0.5
10.0 18.5 0.5
10.0 19.0 0.5
10.0 19.5 0.5
10.0 20.0 0.5
使用Gnuplot,我可以绘制下图:
使用我编写的以下脚本:
set data style lines
set surface
set dgrid3d 30,30
set hidden3d
set ticslevel 0.8
set isosample 40,40
set view 60, 30, 1, 1
set contour base
splot "dataset" using 2:1:($3) notitle
我正在尝试对此图进行一些分析,所以想要将其输入 Matlab,但我不知道如何绘制它。我尝试将数据集导入 Matlab,这就是我所能达到的程度。我正在加载文件并使用以下 Matlab 语句进行绘图:
load data
rangeY = floor(min(data(:,2))):.5:ceil(max(data(:,2)))
rangeX = floor(min(data(:,1))):.5:ceil(max(data(:,1)))
[X,Y] = meshgrid(rangeX,rangeY)
Z = griddata(data(:,1),data(:,2),data(:,3),X,Y, 'cubic')
surf(X,Y,Z)
图片看起来与我截然不同(轴范围、形状等)有人可以告诉我如何获得类似于我通过 Gnuplot 获得的绘图吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
surf
无法立即工作的原因是数据非常嘈杂,如果您调用,您会看到因此,您首先需要平滑数据(我猜这就是gnuplot 函数也可以)。以下是平滑数据的一种方法
The reason
surf
won't work right away is that the data are quite noisy, as you'll see if you callThus, you first need to smoothen the data (which is, I guess, what the gnuplot function does as well). Below is one approach to smoothen the data
我很惊讶你的代码不起作用。我在我的一个数据集上尝试了一下,效果很好。作为第一个答案,我建议您发布数据集的链接(如果不敏感),并尝试其他插值方法(从默认的线性插值方法开始)。
然而,我注意到 griddata 在 XY 域的边界产生了相当多的 NaN,尽管我的数据集非常密集并且在该域中分布良好。我检查了文档,其中提到:
我不认为这是问题的原因,但我仍然怀疑这个函数在非常稀疏的数据集上表现不佳。您应该尝试使用
TriScatteredInterp
来代替,这无论如何都会更快。I am surprised that your code does not work. I tried it on one of my dataset and it worked ok. As a first answer, I would suggest that your post a link to your dataset (if not sensitive), and that you try other methods of interpolation (starting with the default one,
linear
).However, I noticed that
griddata
produced quite a few NaN at the boundaries of the X-Y domain even though my dataset is quite dense and well distributed in that domain. I checked the doc and it is mentioned that:I don't think this is the cause of your problem, but I still suspect this function not to perform very well with very sparse datasets. You should try
TriScatteredInterp
instead, which is anyway faster.