Thread Subject: sort cell struct

Subject: sort cell struct

From: Corinna Schmitt

Date: 22 Jan, 2008 08:10:05

Message: 1 of 8

Hallo,

I have got a cell struct (1x9) which I want to sort.

Example:

input:
'IPF22233.1' 'IPF11819.2' '_' 'HS71' 'SSA1'
'SSA4' '-' '-' '-'

output I want:

'HS71' 'IPF11819.2' 'IPF22233.1' 'SSA1' 'SSA4' '_' '_' '_' '_'

Can anyone help me?

Thanks, Corinna

Subject: sort cell struct

From: Jos

Date: 22 Jan, 2008 08:39:02

Message: 2 of 8

"Corinna Schmitt" <csc@igb.fhg.de> wrote in message
<fn48cs$ebi$1@fred.mathworks.com>...
> Hallo,
>
> I have got a cell struct (1x9) which I want to sort.
>
> Example:
>
> input:
> 'IPF22233.1' 'IPF11819.2' '_' 'HS71' 'SSA1'
> 'SSA4' '-' '-' '-'
>
> output I want:
>
> 'HS71' 'IPF11819.2' 'IPF22233.1' 'SSA1' 'SSA4' '_' '_' '_' '_'
>
> Can anyone help me?
>
> Thanks, Corinna

cell struct??

C = {'IPF22233.1' 'IPF11819.2' '_' 'HS71' 'SSA1' 'SSA4' '-'
'-' '-'}
sort(C)


Do you really want to change dashes into underscores?

Jos

Subject: sort cell struct

From: Corinna Schmitt

Date: 22 Jan, 2008 08:52:01

Message: 3 of 8

Hallo Jos,
> cell struct??
>
> C = {'IPF22233.1' 'IPF11819.2' '_' 'HS71' 'SSA1' 'SSA4' '-'
> '-' '-'}
> sort(C)

Yes it is a cell struct with size 7033x9.

> Do you really want to change dashes into underscores?

No, sorry it was a typing error it should be underscore.
Matlab is running at the moment. I will try your solution later.

Thanks, Corinna

Subject: sort cell struct

From: Yumnam Kirani Singh

Date: 22 Jan, 2008 08:53:58

Message: 4 of 8

Have you tried the sort function?

Subject: sort cell struct

From: Corinna Schmitt

Date: 22 Jan, 2008 10:38:02

Message: 5 of 8

I get the following error message:

??? Error using ==> vertcat
CAT arguments dimensions are not consistent.

Subject: sort cell struct

From: Kris De Gussem

Date: 22 Jan, 2008 10:52:21

Message: 6 of 8

Corinna Schmitt schreef:
> I have got a cell struct (1x9) which I want to sort.
>
> Example:
>
> input:
> 'IPF22233.1' 'IPF11819.2' '_' 'HS71' 'SSA1'
> 'SSA4' '-' '-' '-'
>
> output I want:
>
> 'HS71' 'IPF11819.2' 'IPF22233.1' 'SSA1' 'SSA4' '_' '_' '_' '_'

Try the BTree class (implementation of a binary tree) which is included
in the GSTools toolbox
(http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=9938&objectType=File)

if input is your matrix, you should do something like

tree = BTree(input)
SortedItemsList = GetSortedItemsList (Tree)

the Getitems functions of BTree (help BTree/GetItems) is also usefull,
but not for this issue

BTW: you should really really read a book describing the basics of
matlab. what you describe here is a 1D-cell array

Subject: sort cell struct

From: Kris De Gussem

Date: 22 Jan, 2008 10:53:30

Message: 7 of 8

> tree = BTree(input)
> SortedItemsList = GetSortedItemsList (Tree)

Sorry, it should be

tree = BTree(input)
SortedItemsList = GetSortedItemsList (tree)

Subject: sort cell struct

From: us

Date: 22 Jan, 2008 11:22:03

Message: 8 of 8

"Corinna Schmitt":
<SNIP <jos> simply forgot...

> I get the following error message:
> ??? Error using ==> vertcat
> CAT arguments dimensions are not consistent...

...the continuation syntax

     c={
          'IPF22233.1',...
          'IPF11819.2' '_',...
          'HS71',...
          'SSA1' 'SSA4' '-' '-' '-'
     };
     sort(c)
% - - - HS71 IPF11819.2 IPF22233.1 SSA1 SSA4 _

% -and- a note for mxn cells...

     b=repmat(c,5,1);
     r=reshape(sort(b),[],size(b,2))

us

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
code us 22 Jan, 2008 06:24:59
cell us 22 Jan, 2008 06:24:59
syntax us 22 Jan, 2008 06:24:59
continuation us 22 Jan, 2008 06:24:59
reshape us 22 Jan, 2008 06:24:59
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com