From: Bruno Luong on
"Ulrich" <millim1974(a)yahoo.com> wrote in message <huqpto$mtv$1(a)fred.mathworks.com>...
> anyhow, thx dpd!
>
> It seams to me that Matlab is not able to perform that within one function call!

C={'almo' 'st everything'; 'is poss', 'ible'; 'in sing' 'le line'}
arrayfun(@(r) [C{r,:}], 1:size(C,1),'Unif',false)

Bruno
From: Bruno Luong on
"Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <huqr8s$n6d$1(a)fred.mathworks.com>...
> "Ulrich" <millim1974(a)yahoo.com> wrote in message <huqpto$mtv$1(a)fred.mathworks.com>...
> > anyhow, thx dpd!
> >
> > It seams to me that Matlab is not able to perform that within one function call!
>
> C={'almo' 'st everything'; 'is poss', 'ible'; 'in sing' 'le line'}
> arrayfun(@(r) [C{r,:}], 1:size(C,1),'Unif',false)

Two lines:

B = C';
mat2cell([B{:}],1,sum(cellfun('length',B)))

Bruno
From: Oleg Komarov on
"Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <huqsu3$guj$1(a)fred.mathworks.com>...
> "Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <huqr8s$n6d$1(a)fred.mathworks.com>...
> > "Ulrich" <millim1974(a)yahoo.com> wrote in message <huqpto$mtv$1(a)fred.mathworks.com>...
> > > anyhow, thx dpd!
> > >
> > > It seams to me that Matlab is not able to perform that within one function call!
> >
> > C={'almo' 'st everything'; 'is poss', 'ible'; 'in sing' 'le line'}
> > arrayfun(@(r) [C{r,:}], 1:size(C,1),'Unif',false)
>
> Two lines:
>
> B = C';
> mat2cell([B{:}],1,sum(cellfun('length',B)))
>
> Bruno

Very elegant...but slow:

>> C = repmat({'almo' 'st everything'; 'is poss', 'ible'; 'in sing' 'le line'},10000,1);

t = NaN(2,1);
tic
B = C.';
B = mat2cell([B{:}],1,sum(cellfun('length',B)));
t(1) = toc;

tic
D = cellstrhcat(C).';
t(2) = toc;

isequalwithequalnans(B,D)
ans =
1

t
t =
1.87
0.13

Oleg
From: Bruno Luong on
"Oleg Komarov" <oleg.komarovRemove.this(a)hotmail.it> wrote in message <huqv6h$m2t$1(a)fred.mathworks.com>...
> >
> > Two lines:
> >
> > B = C';
> > mat2cell([B{:}],1,sum(cellfun('length',B)))
> >
> > Bruno
>
> Very elegant...but slow:
>

The slow part is [B{:}], and Jan's submission can nicely fix that:
% http://www.mathworks.com/matlabcentral/fileexchange/26077-cstr2string,

C = repmat({'almo' 'st everything'; 'is poss', 'ible'; 'in sing' 'le line'},10000,1);

tic
B = mat2cell(CStr2String(C.'),1,sum(cellfun('length',C),2));
toc % about 0.1 sec

Thanks Jan,

Bruno
From: Oleg Komarov on
"Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hur1bt$i5n$1(a)fred.mathworks.com>...
> "Oleg Komarov" <oleg.komarovRemove.this(a)hotmail.it> wrote in message <huqv6h$m2t$1(a)fred.mathworks.com>...
> > >
> > > Two lines:
> > >
> > > B = C';
> > > mat2cell([B{:}],1,sum(cellfun('length',B)))
> > >
> > > Bruno
> >
> > Very elegant...but slow:
> >
>
> The slow part is [B{:}], and Jan's submission can nicely fix that:
> % http://www.mathworks.com/matlabcentral/fileexchange/26077-cstr2string,
>
> C = repmat({'almo' 'st everything'; 'is poss', 'ible'; 'in sing' 'le line'},10000,1);
>
> tic
> B = mat2cell(CStr2String(C.'),1,sum(cellfun('length',C),2));
> toc % about 0.1 sec
>
> Thanks Jan,
>
> Bruno

TMW should really implement Jan's solution.

Oleg
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: F28335 plus TIMER1
Next: parking sensor very much