如何从我的surf()数据中创建2D矩阵? [英] How to create a 2D-matrix out of my data for surf()?
问题描述
我有一个25000x3-矩阵,每行包含一个x值,y值和一个z值.现在,我想根据这些内容进行图形化绘制.但是对于例如surf(Z),我必须使用mxn-matrix作为Z,其中m等于x的大小,n等于y的大小.如何将所需的矩阵重塑为所需的mxn矩阵?问题是我的x和y值不是整数,而是浮点数,因此我假设我必须先进行插值.真的吗?我用plot3绘制的数据看起来像:
I have a 25000x3-matrix, with each row containing a x-, a y- and a z-value. Now I wanted to do a graphical plot out of these. But for using for example surf(Z) I have to use a mxn-matrix as Z with m equal the size of x and n equal the size of y. How can I reshape the matrix I have to the needed mxn-matrix? The problem is that my x- and y-values are no ints, but floats, so I assume that I have to do a interpolation first. Is that true? My data plotted with plot3 looks like:
推荐答案
您的x-和y-值不是整数的事实根本不是问题.真正的问题是:您的(x,y)点是否形成网格?
The fact that your x- and y- values are not integers is not a problem at all. The real question is: are your (x,y) points forming a grid, or not ?
-
如果您的点正在形成网格,则必须重塑列以形成m×n数组.您可能需要根据第一列,第二列来
sort
数据,然后使用reshape
函数.
If your points are forming a grid, then you have to reshape your columns to form m-by-n arrays. You may need to
sort
your data according to the first, then second column and then use thereshape
function.
如果您的点未形成网格,则必须进行插值.偶然地 scatterinterpolant类可以很好地帮助您做到这一点.
If your points are not forming a grid, then you will have to make an interpolation. By chance the scatterinterpolant class can nicely help you in doing so.
这篇关于如何从我的surf()数据中创建2D矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!