问题
I have a binary 3D array of the size 1024 by 1024 by 1024. I want to use a function (convhull
), which has the following input:
X is of size mpts-by-ndim, where mpts is the number of points and ndim is the dimension of the space where the points reside, 2 ≦ ndim ≦ 3
How can I reshape my array into the array X which is required by this function?
Maybe "reshape" isn't the best word, because using the "reshape" function isn't enough.
回答1:
What convhull
is looking for is a list of subscripts of nonzero elements in your array. Given a 3D array M
:
[X,Y,Z] = ind2sub(size(M), find(M));
Then you use these in convhull
:
convhull(X, Y, Z);
The lone X
parameter you mention in your question is just these three column vectors concatenated:
X = [X Y Z];
convhull(X);
来源:https://stackoverflow.com/questions/33110501/reshaping-arrays-in-matlab