cat applied to cell array
  Home FAQ Contact Sign in
comp.softsys.matlab only
 
Advanced search
POPULAR GROUPS

more...

comp.softsys.matlab Profile…
 Up
cat applied to cell array         


Author: Matt Fig
Date: Nov 30, 2007 18:36

Hello,

I have a cell array of strings,g, that is 10-by-3, and I
wish to have a cell array of strings that is 10-by-1. The
'rows' of h should be the concatenated strings in g. This
works for what I want:

for ii = 1:length(g),h{ii} = [g{ii,1},g{ii,2},g{ii,3}];end

But is there a way to do this without a loop? I tried
cellfun with @cat, but I cannot pass the dim arg to cat (why
oh why?)

Thanks.
4 Comments
Re: cat applied to cell array         


Author: Jos
Date: Nov 30, 2007 19:15

Sorry, my cell2mat is only working for very specific
formats of g.

Jos
no comments
Re: cat applied to cell array         


Author: Matt Fig
Date: Nov 30, 2007 19:38

Thanks Walter, that works perfectly. To Chris: strcat
doesn't work here because it concatenates to one long
string. Thanks again.
no comments
Re: cat applied to cell array         


Author: checker
Date: Dec 3, 2007 18:34

On Nov 30, 11:38 am, "Matt Fig" yahoo.com> wrote:
> Thanks Walter, that works perfectly. To Chris: strcat
> doesn't work here because it concatenates to one long
> string. Thanks again.

Not to be difficult, but I don't see any difference between the
solution due to your original post and my strcat solution:

%%make up g
for ii =1:10;for jj =1:3
g{ii,jj}=[num2str(ii),num2str(jj)];
end
end

%%OP solution
for ii = 1:length(g),h{ii} = [g{ii,1},g{ii,2},g{ii,3}];end
%%chris solution
h2 = strcat(g(:,1),g(:,2),g(:,3));
%%do they match
strcmp(h,h2)
ans =
Show full article (0.66Kb)
no comments
Re: cat applied to cell array         


Author: Matt Fig
Date: Dec 3, 2007 22:32

checker yahoo.com> wrote in message
<64c2431e-93d3-481d-b03c-a42328622910@b40g2000prf.googlegroups.com>...
> On Nov 30, 11:38 am, "Matt Fig" yahoo.com> wrote:
>> Thanks Walter, that works perfectly. To Chris: strcat
>> doesn't work here because it concatenates to one long
>> string. Thanks again.
>
> Not to be difficult, but I don't see any difference
between the
> solution due to your original post and my strcat solution:
>
> %%make up g
> for ii =1:10;for jj =1:3
> g{ii,jj}=[num2str(ii),num2str(jj)];
> end
> end
>
> %%OP solution
> for ii = 1:length(g),h{ii} = [g{ii,1},g{ii,2},g{ii,3}];end
> %%chris solution ...
Show full article (0.98Kb)
no comments