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:
Indices of vectors

Subject: Indices of vectors

From: David Neibig

Date: 29 Nov, 2010 23:34:05

Message: 1 of 4

Just wondering whether the following is possible: I have vector of values:

A=[ 2 4 6 8 10]
B= find(a)
C=sort(a,'descend')

B generates the vector 1 2 3 4 5
and C generates 10 8 6 4 2

Is there anyway in which the index of a specific number can be translated between the vectors A and C, and whether this is possible for all values of A, even when a has an arbitrary length

Cheers,

David

Subject: Indices of vectors

From: Walter Roberson

Date: 29 Nov, 2010 23:49:39

Message: 2 of 4

On 10-11-29 05:34 PM, David Neibig wrote:
> Just wondering whether the following is possible: I have vector of values:

> A=[ 2 4 6 8 10]
> B= find(a)
> C=sort(a,'descend')

> B generates the vector 1 2 3 4 5 and C generates 10 8 6 4 2

> Is there anyway in which the index of a specific number can be
> translated between the vectors A and C, and whether this is possible for
> all values of A, even when a has an arbitrary length

No. You would not be able to handle duplicate values that way.

However, what you want to do is very easy solved: use the two-output version
of sort.

[C,D] = sort(a,'descend')

Subject: Indices of vectors

From: Roger Stafford

Date: 30 Nov, 2010 00:00:25

Message: 3 of 4

"David Neibig" <david.neibig@student.manchester.ac.uk> wrote in message <id1d9d$sqq$1@fred.mathworks.com>...
> Just wondering whether the following is possible: I have vector of values:
>
> A=[ 2 4 6 8 10]
> B= find(a)
> C=sort(a,'descend')
>
> B generates the vector 1 2 3 4 5
> and C generates 10 8 6 4 2
>
> Is there anyway in which the index of a specific number can be translated between the vectors A and C, and whether this is possible for all values of A, even when a has an arbitrary length
>
> Cheers,
>
> David
- - - - - - -
  I'm having a hard time figuring out what you mean by "the index of a specific number can be translated between the vectors A and C". The nearest I can come to is that after sorting A you would like to have an idea where each number in C came from in A. If that is your question look up the documentation for the second output argument of the 'sort' routine.

Roger Stafford

Subject: Indices of vectors

From: David Neibig

Date: 30 Nov, 2010 12:02:04

Message: 4 of 4

Walter Roberson <roberson@hushmail.com> wrote in message <id1e6o$8ud$1@canopus.cc.umanitoba.ca>...
> On 10-11-29 05:34 PM, David Neibig wrote:
> > Just wondering whether the following is possible: I have vector of values:
>
> > A=[ 2 4 6 8 10]
> > B= find(a)
> > C=sort(a,'descend')
>
> > B generates the vector 1 2 3 4 5 and C generates 10 8 6 4 2
>
> > Is there anyway in which the index of a specific number can be
> > translated between the vectors A and C, and whether this is possible for
> > all values of A, even when a has an arbitrary length
>
> No. You would not be able to handle duplicate values that way.
>
> However, what you want to do is very easy solved: use the two-output version
> of sort.
>
> [C,D] = sort(a,'descend')

The [C,D] = sort(a,'descend') option has allowed me to do exactly what I needed

Thanks
David

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