|
"Medha Jani" <medha_jani@yahoo.com> wrote in message <gptqdh$dr0$1@fred.mathworks.com>...
> Well, what I meant was that A(1,1,1) contains a 1 or 0 depending on certain conditions. 1 indicates that the point exists in the object as a dot in 3D space and 0 indicates otherwise. I wanted to know if there is a way to sort this array according to whether each element contains 1 or 0.
That still leaves you with a lot to explain, Medha. If your three-dimensinal data positions are stored implicitly in the form of the indices of the 1's in your array, how can you do any kind of rearrangement of that array, sorting or otherwise, without destroying that information? It seems to me that instead, you are asking the very different question of how to create a new two-dimensional array, B, which is, say, size N x 3, with N the number of 1's in the array, in which each row stores the specific coordinates - that is to say, the indices - of the N 1-points in the original array. And then you wish to "sort" them in accordance with some, as yet unspecified, criterion as to these indices.
In that case you can do this:
K = find(A(:));
B = zeros(length(K),3);
[B(:,1),B(:,2),B(:,3)] = ind2sub(size(A),K);
along with any kind of sorting in B you wish to do afterwards with the 'sortrows' suggested by John.
Roger Stafford
|