简体   繁体   English

如何在Matlab中从数据文件中绘制3D表面

[英]how to plot 3D surface from a data file in Matlab

I have a data file with 3 columns, x, y, z and I would like to do a 3D plot to visualize the surface. 我有一个包含3列x,y,z的数据文件,我想做一个3D图来可视化表面。

I could have used meshgrid, but the problem is that I only have data for those y that y<=x. 我可以使用meshgrid,但问题是我只有那些y <= x的数据。 Is there a way to do it? 有办法吗?

An example: 一个例子:

x    y    z
============
1    1    0.5
2    1    0.3
2    2    1.2
3    1    1.1
3    2    8.0
3    3    1.4
============

In many cases, a simple solution is to use trisurf. 在许多情况下,一个简单的解决方案是使用trisurf。 For example... 例如...

x = [1, 2, 2, 3, 3, 3];
y = [1, 1, 2, 1, 2, 3];
z = [0.5, 0.3, 1.2, 1.1, 1.8, 1.4];

tri = delaunay(x,y);
trisurf(tri,x,y,z)

替代文字

You can fill the missing values deterministically, just a small script with two nested loops for both x and y . 您可以确定性地填充缺失值,只是一个带有两个嵌套循环的小脚本,用于xy

Otherwise look again at the function meshgrid in the MATLAB documentation. 否则,再次查看MATLAB文档中的函数meshgrid There you see See Also section. 在那里你看到See Also章节。 Not accidentally there is a function griddata listed there. 不小心在那里列出了一个函数griddata That's what you need! 这就是你需要的! I can also recommend gridfit which is even better. 我还可以推荐更好的gridfit

You could fit a surface through the points you have and then graph the surface. 您可以通过所有点拟合曲面,然后绘制曲面图。 I like to use the x2fx function to generate a full quadratic model, then use the \\ operator to fit the data to the model. 我喜欢使用x2fx函数生成完整的二次模型,然后使用\\运算符将数据拟合到模型中。 Do you have any idea about the underlying nature of the surface you're trying to graph? 你对你想要绘制的曲面的基本性质有什么了解吗? Does your data have a lot of noise? 您的数据是否有很多噪音? That 8.0 looks a bit out of place, is that an outlier or is that proper data? 8.0看起来有点不合适,是一个异常值还是正确的数据?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM