user2738748
user2738748

Reputation: 1116

Reshaping arrays in MATLAB

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.

Upvotes: 0

Views: 122

Answers (1)

beaker
beaker

Reputation: 16791

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);

Upvotes: 4

Related Questions