Alex Rivera | Logout

Horizontally concatenate cell array of strings

Asked 2011-02-01T22:46:10.940
11

I wish to horizontally concatenate lines of a cell array of strings as shown below.

start = {'hello','world','test';'join','me','please'}

finish = {'helloworldtest';'joinmeplease'}

Are there any built-in functions that accomplish the above transformation?

Edit
Report

1 Answer

1

A simple way is too loop over the rows

nRows = size(start,1);
finish = cell(nRows,1);

for r = 1:nRows
    finish{r} = [start{r,:}];
end

EDIT

A more involved and slightly harder to read solution that does the same (the general solution is left as an exercise for the reader)

finish = accumarray([1 1 1 2 2 2]',[ 1 3 5 2 4 6]',[],@(x){[start{x}]})

answered 2011-02-01T22:52:49.077

Your Answer