Re: cat applied to cell array



On Nov 30, 10:59 am, rober...@xxxxxxxxxxxxxxxxxx (Walter Roberson)
wrote:
In article <fiphm2$1t...@xxxxxxxxxxxxxxxxxx>,

Matt Fig <spama...@xxxxxxxxx> wrote:
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?)

arrayfun(@(n) [g{n,:}],1:size(g,1),'UniformOutput',0)

--
"Any sufficiently advanced bug is indistinguishable from a feature."
-- Rich Kulawiec

Much less cool looking:

h=strcat(g(:,1),g(:,2),g(:,3))

-Chris
.



Relevant Pages

  • Re: cat applied to cell array
    ... Matt Fig wrote: ... wish to have a cell array of strings that is 10-by-1. ... 'rows' of h should be the concatenated strings in g. ... cellfun with @cat, but I cannot pass the dim arg to cat (why ...
    (comp.soft-sys.matlab)
  • Re: Help on how to add prefix to each element of a string cell array in
    ... a prefix for example 'x' to each of the element of the cell array, ... i.e., i would like the resulted cell array has elements of {'xa1', ... It will give you a cell array of concatenated strings like you want. ...
    (comp.soft-sys.matlab)
  • Re: Help on how to add prefix to each element of a string cell array in
    ... I have a cell array, say a=, and I would like to put ... a prefix for example 'x' to each of the element of the cell array, ... loop in Matlab? ... It will give you a cell array of concatenated strings like you want. ...
    (comp.soft-sys.matlab)