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:
switch x y data in a matrix

Subject: switch x y data in a matrix

From: Jose Miguel

Date: 21 Nov, 2011 20:21:08

Message: 1 of 6

Dear users,

I have the following xyz map:
550000 4625000 0.750
550000 4624900 0.050
550000 4624800 0.050
550000 4624700 0.050
550000 4624600 0.050
.
.
.
550100 4625000 1.25
.
.
.
550200 4625000 0.35
.
.
.
550300 4625000 1.75

I'd like to change the format of the map (keeping Y fixed and X varying) and obviously keep the information of the 3rd column to its original value
550000 4625000 0.75
550100 4625000 1.25
550200 4625000 0.35
550300 4625000 1.75

Would you have any suggestions to do this efficiently? The map is very large and my algorithm is just too unefficient,

Thank you very much for your help!
Regards
Jose,

Subject: switch x y data in a matrix

From: dpb

Date: 21 Nov, 2011 21:06:12

Message: 2 of 6

On 11/21/2011 2:21 PM, Jose Miguel wrote:
...

> I'd like to change the format of the map (keeping Y fixed and X varying)
> and obviously keep the information of the 3rd column to its original value
> 550000 4625000 0.75
> 550100 4625000 1.25
> 550200 4625000 0.35
> 550300 4625000 1.75
>
> Would you have any suggestions to do this efficiently? The map is very
> large and my algorithm is just too unefficient,
...

Not sure just how you wish to rearranage but look at sort() w/ the
optional return values to get a order vector on the second column to use.

--

Subject: switch x y data in a matrix

From: Roger Stafford

Date: 21 Nov, 2011 21:55:09

Message: 3 of 6

"Jose Miguel " <josemijauregui@hotmail.com> wrote in message <jaebrk$p3b$1@newscl01ah.mathworks.com>...
> Dear users,
>
> I have the following xyz map:
> 550000 4625000 0.750
> 550000 4624900 0.050
> 550000 4624800 0.050
> 550000 4624700 0.050
> 550000 4624600 0.050
> .
> .
> .
> 550100 4625000 1.25
> .
> .
> .
> 550200 4625000 0.35
> .
> .
> .
> 550300 4625000 1.75
>
> I'd like to change the format of the map (keeping Y fixed and X varying) and obviously keep the information of the 3rd column to its original value
> 550000 4625000 0.75
> 550100 4625000 1.25
> 550200 4625000 0.35
> 550300 4625000 1.75
>
> Would you have any suggestions to do this efficiently? The map is very large and my algorithm is just too unefficient,
>
> Thank you very much for your help!
> Regards
> Jose,
- - - - - - - -
  Your explanation is rather lacking in clarity, Jose, so the following is simply a wild guess as what you want. Let A be the original array and B the modified one.

 [~,m] = unique(A(:,1),'first');
 B = A(m,:);

This selects out of A those rows containing the first of each unique value in the first column.

  I suspect that the odds are against this being what you actually want. If so, it is up to you to give a much more detailed and accurate description.

Roger Stafford

Subject: switch x y data in a matrix

From: Bruno Luong

Date: 22 Nov, 2011 06:53:08

Message: 4 of 6

 A=[550000 4625000 0.750
550000 4624900 0.050
550000 4624800 0.050
550000 4624700 0.050
550000 4624600 0.050
550100 4625000 0.750
550100 4624900 0.050
550200 4624800 0.050
550200 4624700 0.050
550200 4624600 0.050]

sortrows(A,2)

% Bruno

Subject: switch x y data in a matrix

From: Jose Miguel

Date: 22 Nov, 2011 09:34:10

Message: 5 of 6

Thank you all for your answers,

Sorry for the lack of definition,
The problem has been solved with the function sortrows, thanks!!
I couldn't remember this function, this is what I needed

Regards,
Jose

Subject: switch x y data in a matrix

From: Jose Miguel

Date: 22 Nov, 2011 09:36:08

Message: 6 of 6

Thanks to all of you for your answers,
Sorry for the lack of definition, my mistake
The problem has been solved with the function sortrows,
Thanks,
Regards!

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