|
|
Up |
|
  |
Author: Matt FigMatt 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 |
|
  |
Author: JosJos Date: Nov 30, 2007 19:15
Sorry, my cell2mat is only working for very specific
formats of g.
Jos
|
| |
|
| | no comments |
|
  |
Author: Matt FigMatt 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 |
|
  |
Author: checkerchecker 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 |
|
  |
|
|
  |
Author: Matt FigMatt Fig Date: Dec 3, 2007 22:32
> 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 |
|
|