Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于Matlab的单元阵列组合列_Matlab - Fatal编程技术网

基于Matlab的单元阵列组合列

基于Matlab的单元阵列组合列,matlab,Matlab,我有一个具有动态行大小和列大小的2D单元格数组。一个例子: cell3 = [{'abe' 'basdasd' 'ceee'}; {'d' 'eass' 'feeeeeeeeee'}] 给出:(尺寸为2×3) 我希望能够组合这些列并重新生成聚合字符串单元格数组,其中每个字符串由单个空格分隔。你知道怎么做吗 所以我想要的结果是: 'abe basdasd ceee' 'd eass feeeeeeeeee' 最终尺寸为2乘1 这可能吗?在循环中或通过cellfun应用strjoi

我有一个具有动态行大小和列大小的2D单元格数组。一个例子:

cell3 = [{'abe' 'basdasd' 'ceee'}; {'d' 'eass' 'feeeeeeeeee'}]
给出:(尺寸为2×3)

我希望能够组合这些列并重新生成聚合字符串单元格数组,其中每个字符串由单个空格分隔。你知道怎么做吗

所以我想要的结果是:

'abe basdasd ceee'       
'd eass feeeeeeeeee'
最终尺寸为2乘1


这可能吗?

在循环中或通过
cellfun
应用
strjoin
。后者:

>> cellRows = mat2cell(cell3,ones(size(cell3,1),1),size(cell3,2));
>> out = cellfun(@strjoin,cellRows,'uni',0)
out = 
    'abe basdasd ceee'
    'd eass feeeeeeeeee'

不带循环的解决方案或
cellfun

[m n] = size(cell3);
cellCols = mat2cell(cell3,m,ones(1,n)); %// group by columns
cellColsSpace(1:2:2*size(cell3,2)-1) = cellCols; %// make room (columns)...
cellColsSpace(2:2:2*size(cell3,2)-1) = {{' '}}; %// ...to introduce spaces
%// Note that a cell within cell is needed, because of how strcat works.
result = strcat(cellColsSpace{:});

+1.如果不介意把事情复杂化一点,可以使用strcat避免循环
[m n] = size(cell3);
cellCols = mat2cell(cell3,m,ones(1,n)); %// group by columns
cellColsSpace(1:2:2*size(cell3,2)-1) = cellCols; %// make room (columns)...
cellColsSpace(2:2:2*size(cell3,2)-1) = {{' '}}; %// ...to introduce spaces
%// Note that a cell within cell is needed, because of how strcat works.
result = strcat(cellColsSpace{:});