MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   水平串联字符串的单元格数组 (https://www.labfans.com/bbs/showthread.php?t=26261)

poster 2019-12-14 20:13

水平串联字符串的单元格数组
 
我希望水平连接字符串单元格数组的行,如下所示。

start = {'hello','world','test';'join','me','please'} finish = {'helloworldtest';'joinmeplease'} 是否有内置函数可以完成上述转换?



[B]回答:[/B]

一种简单的方法就是遍历行

nRows = size(start,1); finish = cell(nRows,1); for r = 1:nRows finish{r} = [start{r,:}]; end [B]编辑[/B]

更具参与性且稍难阅读的解决方案,其功能相同(一般解决方案留给读者练习)

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



[url=https://stackoverflow.com/questions/4868841]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 23:25

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.