合并单元格阵列Matlab的列 [英] Combine Columns of Cell Array Matlab

查看:122
本文介绍了合并单元格阵列Matlab的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a 2D cell array with dynamic row sizes and column sizes. One example:

cell3 = [{'abe' 'basdasd' 'ceee'}; {'d' 'eass' 'feeeeeeeeee'}]

赠予:(尺寸为2 x 3)

Gives: (with dimension 2 by 3)

'abe'    'basdasd'    'ceee'       
'd'      'eass'       'feeeeeeeeee'

我希望能够合并列并复制聚合的字符串单元格数组,其中每个字符串都由单个空格分隔.知道怎么做吗?

I want to be able to combine the columns and reproduce a aggregate string cell array where each string is separated by a single white space. Any idea how to do that?

所以我正在寻找的输出是:

So the output i am looking for is:

'abe basdasd ceee'       
'd eass feeeeeeeeee'

最终尺寸为2 x 1.

The final dimension is 2 by 1.

这可能吗?

推荐答案

以循环方式或通过cellfun应用strjoin.后者:

Apply strjoin either in a loop or via cellfun. The latter:

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

这篇关于合并单元格阵列Matlab的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆