Horizontally concatenate cell array of strings

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?

Answers


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}]})


There is an easy non-loop way you can do this using the functions NUM2CELL and STRCAT:

>> finish = num2cell(start,1);
>> finish = strcat(finish{:})

finish = 

    'helloworldtest'
    'joinmeplease'

I think you want is that these two are concatenated as a single cell array. Try using this code, works for me.

'x = [{start}, {finish}];'


Need Your Help

iPhone 4 Tab Bar Icons

iphone icons tabbar retina-display

I'm having some issues getting high resolution tab bar icons displaying correctly for iPhone 4. Basically I'm using the Apple guidelines of 96 x 64 for high resolution icons, but when I do this, m...