水平串联字符串的单元格数组 [英] 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?
推荐答案
一种简单的方法也是在行上循环
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
编辑
一种更复杂,更难读的解决方案(一般解决方案留给读者练习)
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}]}
)
这篇关于水平串联字符串的单元格数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文