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 th开发者_JAVA百科at accomplish the above transformation?
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'
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}]}
)
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}];'
精彩评论