Reshaping arrays in MATLAB

ε祈祈猫儿з 提交于 2019-12-13 04:37:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!