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:
Reposted Thread on Sorting Vectors

Subject: Reposted Thread on Sorting Vectors

From: Martin

Date: 17 Feb, 2010 19:44:05

Message: 1 of 3

Please don't spam reply my messages. This is not homework. I am not a matab student, I am using matlab to resolve a very large (1000s) set of data.

I would appreciate any help with this:

I enter the following code:

a=[10 30 80 70 40 90 60 20 80]
[aa,bb]=sort(a)
cc=[1:1:9]
dd=[cc-bb]

asking for dd gives me the string

0 -6 1 -1 -4 -1 3 5 3

How do I ask matlab to now put the postion moves under the respective numbers in string a? So it displays as:

0 1 5 3 -1 3 -1 -6 -4

Such that the number of moves made by the number to put it in orde are placed in the position of the respective number in string a, rather than in the prosition of its number once arranged in order.

I hope this makes sense? Any help very much appreciated.

thank you

Subject: Reposted Thread on Sorting Vectors

From: Sadik

Date: 17 Feb, 2010 20:06:03

Message: 2 of 3

Hi Martin,

You should use the following two lines:

[kk,mm] = sort(bb);
ff = dd(mm);

ff is what you are looking for.

By the way,

1. My dd is different than yours. It is

0 -6 1 -1 -2 2 4 -1 3

2. A caveat: You have two 80s in your array.

Best.

"Martin " <oneaccount@hotmail.co.uk> wrote in message <hlhgu5$smt$1@fred.mathworks.com>...
> Please don't spam reply my messages. This is not homework. I am not a matab student, I am using matlab to resolve a very large (1000s) set of data.
>
> I would appreciate any help with this:
>
> I enter the following code:
>
> a=[10 30 80 70 40 90 60 20 80]
> [aa,bb]=sort(a)
> cc=[1:1:9]
> dd=[cc-bb]
>
> asking for dd gives me the string
>
> 0 -6 1 -1 -4 -1 3 5 3
>
> How do I ask matlab to now put the postion moves under the respective numbers in string a? So it displays as:
>
> 0 1 5 3 -1 3 -1 -6 -4
>
> Such that the number of moves made by the number to put it in orde are placed in the position of the respective number in string a, rather than in the prosition of its number once arranged in order.
>
> I hope this makes sense? Any help very much appreciated.
>
> thank you

Subject: Reposted Thread on Sorting Vectors

From: Martin

Date: 17 Feb, 2010 21:10:27

Message: 3 of 3

Thanks Sadik, this worked perfectly!

I really appreciate your help!

all the best

Tags for this Thread

No tags are associated with 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