From: davidebacc Bacchini on
Hello,
what i need is to extract the indixes of the n greatest elements of a vector. Is there a function to do it?
Example:
vector = [3 2 5 9 1 4 6]
ngreat(1)
ans = 4
ngreat(3)
ans = [3 4 7]

Thank you
From: James Tursa on
"davidebacc Bacchini" <davidebacc(a)hotmail.com> wrote in message <hjoq5i$34f$1(a)fred.mathworks.com>...
> Hello,
> what i need is to extract the indixes of the n greatest elements of a vector. Is there a function to do it?
> Example:
> vector = [3 2 5 9 1 4 6]
> ngreat(1)
> ans = 4
> ngreat(3)
> ans = [3 4 7]
>
> Thank you

What's wrong with sorting?

James Tursa
From: davidebacc Bacchini on
"James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <hjor5g$4kg$1(a)fred.mathworks.com>...
> What's wrong with sorting?
>
> James Tursa

I have another vector and i want to extract the values that correspond to the n greatest values in the first vector

vector = [3 2 5 9 1 4 6]

vector2=[0.9 0.3 0.1 0.5 0.7 0.9 0.4]

For instance I want the 3 elements who correspond to the 3 greatest elements in the first vector. I need the values 0.1 0.5 0.4
From: James Tursa on
"davidebacc Bacchini" <davidebacc(a)hotmail.com> wrote in message <hjos1k$ic9$1(a)fred.mathworks.com>...
> "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <hjor5g$4kg$1(a)fred.mathworks.com>...
> > What's wrong with sorting?
> >
> > James Tursa
>
> I have another vector and i want to extract the values that correspond to the n greatest values in the first vector
>
> vector = [3 2 5 9 1 4 6]
>
> vector2=[0.9 0.3 0.1 0.5 0.7 0.9 0.4]
>
> For instance I want the 3 elements who correspond to the 3 greatest elements in the first vector. I need the values 0.1 0.5 0.4

Again, what's wrong with sorting? Look at the doc for sort, particularly this syntax:

[B,IX] = sort(...)

James Tursa
From: davidebacc Bacchini on
"James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <hjoso4$g6s$1(a)fred.mathworks.com>...

> Again, what's wrong with sorting? Look at the doc for sort, particularly this syntax:
>
> [B,IX] = sort(...)
>
> James Tursa

You are right, that's exactly what i needed
Thank you very much