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 a vector string

Subject: Sorting a vector string

From: Martin

Date: 17 Feb, 2010 19:13:20

Message: 1 of 11

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: Sorting a vector string

From: ImageAnalyst

Date: 17 Feb, 2010 19:20:37

Message: 2 of 11

This is the identical problem that your classmate posted in
http://groups.google.com/group/comp.soft-sys.matlab/browse_frm/thread/5ee6f7719b12a525/0b09942c51a012a2?hl=en#0b09942c51a012a2
Neither one of you admitted in advance that it was your homework.

Subject: Sorting a vector string

From: Martin

Date: 17 Feb, 2010 19:47:03

Message: 3 of 11

Your deductions are wrong.

This is not homework. We are not matlab students.

help appreciated?

Subject: Sorting a vector string

From: Oleg Komarov

Date: 17 Feb, 2010 19:53:05

Message: 4 of 11

"Martin " <oneaccount@hotmail.co.uk> wrote in message <hlhh3m$al8$1@fred.mathworks.com>...
> Your deductions are wrong.
>
> This is not homework. We are not matlab students.
>
> help appreciated?
In the post linked above I already answered.
You can answer too.

Oleg

Subject: Sorting a vector string

From: Martin

Date: 17 Feb, 2010 20:18:18

Message: 5 of 11

thanks for your pointer.

I tried this and got the string:

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

which is not the string that I want. I am hoping to resolve such that I get the string depicted in the question.

Thanks again.

Subject: Sorting a vector string

From: Oleg Komarov

Date: 17 Feb, 2010 20:26:02

Message: 6 of 11

"Martin " <oneaccount@hotmail.co.uk> wrote in message <hlhf4g$19g$1@fred.mathworks.com>...
> 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

"Martin " <oneaccount@hotmail.co.uk> wrote in message <hlhiua$bl3$1@fred.mathworks.com>...
> thanks for your pointer.
>
> I tried this and got the string:
>
> 0 5 -6 -4 3 3 -1 1 -1
>
> which is not the string that I want. I am hoping to resolve such that I get the string depicted in the question.
>
> Thanks again.

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 array:
 0 -6 1 -1 -2 2 4 -1 3
as opposed to your example.

Oleg

Subject: Sorting a vector string

From: Martin

Date: 17 Feb, 2010 20:41:21

Message: 7 of 11

my apologies: The first string should read

a=[10 30 80 70 40 90 60 20 50]

not the last number has changed from 80 to 50 such that i have the string 10 thru 90.

Subject: Sorting a vector string

From: Sadik

Date: 17 Feb, 2010 20:51:24

Message: 8 of 11

Part of my answer to another question of yours with title "Reposted..."

Hi Martin,

You should use the following two lines:

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

ff is what you are looking for.

Best.




"Martin " <oneaccount@hotmail.co.uk> wrote in message <hlhk9h$9l1$1@fred.mathworks.com>...
> my apologies: The first string should read
>
> a=[10 30 80 70 40 90 60 20 50]
>
> not the last number has changed from 80 to 50 such that i have the string 10 thru 90.

Subject: Sorting a vector string

From: Oleg Komarov

Date: 17 Feb, 2010 20:55:21

Message: 9 of 11

"Martin " <oneaccount@hotmail.co.uk> wrote in message <hlhk9h$9l1$1@fred.mathworks.com>...
> my apologies: The first string should read
>
> a=[10 30 80 70 40 90 60 20 50]
>
> not the last number has changed from 80 to 50 such that i have the string 10 thru 90.

two alternatives:

dd(cc-dd)=dd;
dd(bb) = dd;
Oleg

Subject: Sorting a vector string

From: Martin

Date: 17 Feb, 2010 21:09:24

Message: 10 of 11

Hi Sadik,

Many thanks, that worked perfectly!

Thanks to all for your help.

Subject: Sorting a vector string

From: Martin

Date: 17 Feb, 2010 21:13:05

Message: 11 of 11

Thanks Oleg for your patience with my errors!

dd(cc)=dd gave me exactly what I want

thank you for your help

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