Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Sorting 3D Data

Subject: Sorting 3D Data

From: Medha Jani

Date: 19 Mar, 2009 14:18:02

Message: 1 of 8

I have my data as a 3d matrix A(150x120x240) or A(i,j,k) containing positional coordinates x,y,z of an object. Here, the element A(1,1,1) contains the x-,y- and z-coordinates of an object. I want to sort this data, but there is one problem. I cannot use the sort functions as that would lead to complete rearrangement of coordinates and the corresponding positions of x,y and z would be lost. Can anyone suggest a way that I can sort this data according to either the first dimension or second dimension or third dimension, but the corresponding other two dimensions must also change with it and the positional coordinates are not lost.

Subject: Sorting 3D Data

From: John D'Errico

Date: 19 Mar, 2009 14:59:01

Message: 2 of 8

"Medha Jani" <medha_jani@yahoo.com> wrote in message <gptk6q$4jp$1@fred.mathworks.com>...
> I have my data as a 3d matrix A(150x120x240) or A(i,j,k) containing positional coordinates x,y,z of an object. Here, the element A(1,1,1) contains the x-,y- and z-coordinates of an object. I want to sort this data, but there is one problem. I cannot use the sort functions as that would lead to complete rearrangement of coordinates and the corresponding positions of x,y and z would be lost. Can anyone suggest a way that I can sort this data according to either the first dimension or second dimension or third dimension, but the corresponding other two dimensions must also change with it and the positional coordinates are not lost.

help sortrows

HTH,
John

Subject: Sorting 3D Data

From: Medha Jani

Date: 19 Mar, 2009 15:07:01

Message: 3 of 8

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <gptmjl$ofq$1@fred.mathworks.com>...
> "Medha Jani" <medha_jani@yahoo.com> wrote in message <gptk6q$4jp$1@fred.mathworks.com>...
> > I have my data as a 3d matrix A(150x120x240) or A(i,j,k) containing positional coordinates x,y,z of an object. Here, the element A(1,1,1) contains the x-,y- and z-coordinates of an object. I want to sort this data, but there is one problem. I cannot use the sort functions as that would lead to complete rearrangement of coordinates and the corresponding positions of x,y and z would be lost. Can anyone suggest a way that I can sort this data according to either the first dimension or second dimension or third dimension, but the corresponding other two dimensions must also change with it and the positional coordinates are not lost.
>
> help sortrows
>
> HTH,
> John

Thanx a Lot!

Subject: Sorting 3D Data

From: Medha Jani

Date: 19 Mar, 2009 15:13:03

Message: 4 of 8

"Medha Jani" <medha_jani@yahoo.com> wrote in message <gptn2l$rme$1@fred.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in message <gptmjl$ofq$1@fred.mathworks.com>...
> > "Medha Jani" <medha_jani@yahoo.com> wrote in message <gptk6q$4jp$1@fred.mathworks.com>...
> > > I have my data as a 3d matrix A(150x120x240) or A(i,j,k) containing positional coordinates x,y,z of an object. Here, the element A(1,1,1) contains the x-,y- and z-coordinates of an object. I want to sort this data, but there is one problem. I cannot use the sort functions as that would lead to complete rearrangement of coordinates and the corresponding positions of x,y and z would be lost. Can anyone suggest a way that I can sort this data according to either the first dimension or second dimension or third dimension, but the corresponding other two dimensions must also change with it and the positional coordinates are not lost.
> >
> > help sortrows
> >
> > HTH,
> > John
>
But sortrows doesnt seem to work for 3D matrices...Any help with that??

Subject: Sorting 3D Data

From: John D'Errico

Date: 19 Mar, 2009 15:26:02

Message: 5 of 8

"Medha Jani" <medha_jani@yahoo.com> wrote in message <gptndv$mq8$1@fred.mathworks.com>...
> "Medha Jani" <medha_jani@yahoo.com> wrote in message <gptn2l$rme$1@fred.mathworks.com>...
> > "John D'Errico" <woodchips@rochester.rr.com> wrote in message <gptmjl$ofq$1@fred.mathworks.com>...
> > > "Medha Jani" <medha_jani@yahoo.com> wrote in message <gptk6q$4jp$1@fred.mathworks.com>...
> > > > I have my data as a 3d matrix A(150x120x240) or A(i,j,k) containing positional coordinates x,y,z of an object. Here, the element A(1,1,1) contains the x-,y- and z-coordinates of an object. I want to sort this data, but there is one problem. I

Let me back up, and read your question more
carefully.

A(1,1,1) is a scalar. How can it contain the
(x,y,z) coordinates?

John

Subject: Sorting 3D Data

From: Roger Stafford

Date: 19 Mar, 2009 15:50:19

Message: 6 of 8

"Medha Jani" <medha_jani@yahoo.com> wrote in message <gptk6q$4jp$1@fred.mathworks.com>...
> I have my data as a 3d matrix A(150x120x240) or A(i,j,k) containing positional coordinates x,y,z of an object. Here, the element A(1,1,1) contains the x-,y- and z-coordinates of an object. I want to sort this data, but there is one problem. I cannot use the sort functions as that would lead to complete rearrangement of coordinates and the corresponding positions of x,y and z would be lost. Can anyone suggest a way that I can sort this data according to either the first dimension or second dimension or third dimension, but the corresponding other two dimensions must also change with it and the positional coordinates are not lost.

  There seems to be some confusion here, Medha. There is a difference between a three-dimensional array and an array which contains Cartesian coordinates of spatially three-dimensional data. You speak of a 150x120x240 array containing positional coordinates. In what manner are these coordinates stored in this array? As John has stated, your statement that A(1,1,1) contains x, y, and z coordinates cannot be correct. It is a simple scalar. Each individual coordinate must occupy a single scalar in A. How are the three coordinates of any one point arranged in A?

Roger Stafford

Subject: Sorting 3D Data

From: Medha Jani

Date: 19 Mar, 2009 16:04:01

Message: 7 of 8

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gptpjq$hv8$1@fred.mathworks.com>...
> "Medha Jani" <medha_jani@yahoo.com> wrote in message <gptk6q$4jp$1@fred.mathworks.com>...
> > I have my data as a 3d matrix A(150x120x240) or A(i,j,k) containing positional coordinates x,y,z of an object. Here, the element A(1,1,1) contains the x-,y- and z-coordinates of an object. I want to sort this data, but there is one problem. I cannot use the sort functions as that would lead to complete rearrangement of coordinates and the corresponding positions of x,y and z would be lost. Can anyone suggest a way that I can sort this data according to either the first dimension or second dimension or third dimension, but the corresponding other two dimensions must also change with it and the positional coordinates are not lost.
>
> There seems to be some confusion here, Medha. There is a difference between a three-dimensional array and an array which contains Cartesian coordinates of spatially three-dimensional data. You speak of a 150x120x240 array containing positional coordinates. In what manner are these coordinates stored in this array? As John has stated, your statement that A(1,1,1) contains x, y, and z coordinates cannot be correct. It is a simple scalar. Each individual coordinate must occupy a single scalar in A. How are the three coordinates of any one point arranged in A?
>
> Roger Stafford

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.

Subject: Sorting 3D Data

From: Roger Stafford

Date: 19 Mar, 2009 18:09:01

Message: 8 of 8

"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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us