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

Subject: sorting a vector

From: Teddy

Date: 7 Apr, 2009 05:53:05

Message: 1 of 5

[v,e]=eig(d);
e=diag(e);
[Y,I]=sort(-imag(e)); <- From this line
xs=v(:,I);
es=e(I);

Hi I am a beginner at matlab.

I am not sure what actually happens from 3rd line from above..
trying "help sort" does not help too much...
can anyone explain what each command does clearly?
Thanks

Subject: sorting a vector

From: Gavrilo Bozovic

Date: 7 Apr, 2009 07:02:04

Message: 2 of 5

Teddy <skim178@ec.auckland.ac.nz> wrote in message <3544555.8254.1239083615799.JavaMail.jakarta@nitrogen.mathforum.org>...
> [v,e]=eig(d);
> e=diag(e);
> [Y,I]=sort(-imag(e)); <- From this line
> xs=v(:,I);
> es=e(I);
>
> Hi I am a beginner at matlab.
>
> I am not sure what actually happens from 3rd line from above..
> trying "help sort" does not help too much...
> can anyone explain what each command does clearly?
> Thanks

"sort" simply sorts the vector...

a = [1 3 2 5 4];
b = sort(a);

--> b = [1 2 3 4 5];

so what don't you understand?

Subject: sorting a vector

From: Jos

Date: 7 Apr, 2009 09:57:01

Message: 3 of 5

Teddy <skim178@ec.auckland.ac.nz> wrote in message <3544555.8254.1239083615799.JavaMail.jakarta@nitrogen.mathforum.org>...
> [v,e]=eig(d);
> e=diag(e);
> [Y,I]=sort(-imag(e)); <- From this line
> xs=v(:,I);
> es=e(I);
>
> Hi I am a beginner at matlab.
>
> I am not sure what actually happens from 3rd line from above..
> trying "help sort" does not help too much...
> can anyone explain what each command does clearly?
> Thanks

See & learn by removing the semi-colons and break down the code even further:

[v,e]=eig(d)
e=diag(e)
e2 = imag(e)
e3 = -e2
[Y,I]=sort(e3)
xs=v(:,I)
es=e(I)

hth
Jos

Subject: sorting a vector

From: dpb

Date: 8 Apr, 2009 01:46:01

Message: 4 of 5

Teddy wrote:
> [v,e]=eig(d);
> e=diag(e);
> [Y,I]=sort(-imag(e)); <- From this line
> xs=v(:,I);
> es=e(I);
>
> Hi I am a beginner at matlab.
>
> I am not sure what actually happens from 3rd line from above..
> trying "help sort" does not help too much...
> can anyone explain what each command does clearly?
> Thanks

I'd suggest start w/

[Y,I]=sort(rand(1,10))

and see what happens to understand what sort() returns...

--

Subject: sorting a vector

From: Matt Fig

Date: 8 Apr, 2009 02:41:01

Message: 5 of 5

dpb <none@non.net> wrote in message <grgvn1$b58$2@aioe.org>...

> I'd suggest start w/
>
> [Y,I]=sort(rand(1,10))
>
> and see what happens to understand what sort() returns...


Except that without seeing the input clearly, it is hard to understand the output. Try this:

x = randperm(5)
[y,index]=sort(x)

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