Thread Subject: Sorting a cell array according to another

Subject: Sorting a cell array according to another

From: steeve_dun

Date: 8 Nov, 2009 16:23:18

Message: 1 of 5

Hi,
I have 2 cell arrays X and Y.
I’ve sorted X with [a idx]=sort(X) and I would like Y to be sorted
according to idx.
Can anybody help please?
Thanks in advance

Subject: Sorting a cell array according to another

From: Chan Huntington

Date: 8 Nov, 2009 16:57:43

Message: 2 of 5

Would y(idx) do what you need?

Subject: Sorting a cell array according to another

From: Miroslav Balda

Date: 8 Nov, 2009 17:51:02

Message: 3 of 5

steeve_dun <steeve_dun@yahoo.fr> wrote in message <92bcbdae-a733-4aab-81c6-f7f15b418fdc@m16g2000yqc.googlegroups.com>...
> Hi,
> I have 2 cell arrays X and Y.
> I’ve sorted X with [a idx]=sort(X) and I would like Y to be sorted
> according to idx.
> Can anybody help please?
> Thanks in advance

Hi,

try this (for column vectors):

[xs,idx]=sort(x{:});
y{:}(idx,:);

Mira

Subject: Sorting a cell array according to another

From: steeve_dun

Date: 8 Nov, 2009 18:39:40

Message: 4 of 5

On 8 nov, 18:51, "Miroslav Balda" <miroslav.nos...@balda.cz> wrote:
> steeve_dun <steeve_...@yahoo.fr> wrote in message <92bcbdae-a733-4aab-81c6-f7f15b418...@m16g2000yqc.googlegroups.com>...
> > Hi,
> > I have 2 cell arrays X and Y.
> > I’ve sorted X with [a idx]=sort(X) and I would like Y to be sorted
> > according to idx.
> > Can anybody help please?
> > Thanks in advance
>
> Hi,
>
> try this (for column vectors):
>
> [xs,idx]=sort(x{:});
> y{:}(idx,:);
>
> Mira

Thank you, that was very helpful

Subject: Sorting a cell array according to another

From: Loren Shure

Date: 9 Nov, 2009 14:24:56

Message: 5 of 5

In article <hd70e6$kf6$1@fred.mathworks.com>, miroslav.nospam@balda.cz
says...
> steeve_dun <steeve_dun@yahoo.fr> wrote in message <92bcbdae-a733-4aab-81c6-f7f15b418fdc@m16g2000yqc.googlegroups.com>...
> > Hi,
> > I have 2 cell arrays X and Y.
> > I’ve sorted X with [a idx]=sort(X) and I would like Y to be sorted
> > according to idx.
> > Can anybody help please?
> > Thanks in advance
>
> Hi,
>
> try this (for column vectors):
>
> [xs,idx]=sort(x{:});
> y{:}(idx,:);
>
> Mira
>

I think you can also do
y(idx,:) and that should be faster.

--
Loren
http://blogs.mathworks.com/loren

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com