Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: sorting cell
Date: Sun, 28 Jun 2009 13:14:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 58
Message-ID: <h27qap$q8h$1@fred.mathworks.com>
References: <h275h5$5tq$1@fred.mathworks.com> <30304573.41024.1246178507734.JavaMail.jakarta@nitrogen.mathforum.org> <h27f6i$e6u$1@fred.mathworks.com> <h27n99$fbi$1@fred.mathworks.com> <h27o95$hnd$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1246194841 26897 172.30.248.35 (28 Jun 2009 13:14:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 28 Jun 2009 13:14:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1886545
Xref: news.mathworks.com comp.soft-sys.matlab:551205


"us " <us@neurol.unizh.ch> wrote in message <h27o95$hnd$1@fred.mathworks.com>...
> "Oleg Komarov" <oleg.komarov@hotmail.it> wrote in message <h27n99$fbi$1@fred.mathworks.com>...
> > I feel kinda sorry and i think that one chance may be given from time to time.
> > To: Parham
> > Read the code and the help files of the functions in order to understand how they work. Don't ask just to solve problems for u. This is a long run-advice.
> > 
> > % Your example:
> > c={{83 83 83 84 85 86 86 86 94} {15 18 19 19 20 12 15 16 15} {'b' 'c' 'a' 't' 'f' 'r' 'd' 'r' 'x'}};
> > 
> > % Counts the number of types of information
> > Col = size(c,2);
> > 
> > % CONDITION if u have all "Col" datatypes for every entry
> > if ~all(diff(cellfun(@numel, c))) 
> >     % Flattening (this is my/Bruno's :) function) http://www.mathworks.com/matlabcentral/fileexchange/24544
> >     c = flatcell(c);
> >     % Reshaping
> >     c = reshape(c, [], Col);
> >     % Sorting by the first and then by the second
> >     c = sortrows(c, [1 2]);
> > else
> >     display('Missing data')
> > end
> > 
> > 
> > By the way, there is also this tool that may come in handy http://www.mathworks.com/matlabcentral/fileexchange/14225
> 
> why...
> the OP was asked to look at SORTROWS and CAT, which do the job just fine...
> 
> one of the solutions
> 
> % the (ori) data
>      c={     % <- 1 x 3 cell array of cells
>           {83 85 84 86 86 86 94 83 83},...
>           {19 20 19 12 16 15 13 18 15},...
>           {'b' 'c' 'a' 't' 'f' 'r' 'd' 'r' 'x'}
>      };
> % the engine
>      cc=cat(1,c{:}).';
>      r=sortrows(cc,[1,2]);
> % the result
>      disp(r);
> %{
>           [83]    [15]    'x'
>           [83]    [18]    'r'
>           [83]    [19]    'b'
>           [84]    [19]    'a'
>           [85]    [20]    'c'
>           [86]    [12]    't'
>           [86]    [15]    'r'
>           [86]    [16]    'f'
>           [94]    [13]    'd'
> %}
> 
> us

Deeply right!