arrays - 使用 for 循环连接多个元胞数组?

标签 arrays matlab concatenation cell-array

我有一个包含 750 个“文档”的元胞数组(单个元胞数组内有 750 个单词数组)。我试图将所有单词连接起来形成一个数组。 到目前为止,我知道我需要使用 for 循环来迭代每个数组并附加到最​​后一个数组的末尾,但是我的代码给了我错误的答案:

list = cell(1,1);
    for i = 1:length(docs)
   prevList = list;
    list = [prevList;docs{i}];
end

我的想法是我的列表初始化是不正确的,因为它产生:

    [1x1635 char]
    [1x1476 char]
    [1x531  char]
    [1x103  char]
    [1x1725 char]
    [1x344  char]
    [1x463  char]
    [1x739  char]
    [1x762  char]
    [1x1139 char]
    [1x89   char]
    [1x361  char]
    [1x334  char]
    [1x520  char]
    [1x219  char]
and so forth...

而不是单词列表。

如果有人可以帮助我,我将非常感激。

最佳答案

不需要for循环。让我们用一个小例子:

str1 = 'The quick brown ';
str2 = 'fox jumped over the ';
str3 = 'lazy dog. '
docs = {str1;str2;str3} % Your cell array containing arrays of text in each row

docs_cat = [docs{:}] % Concatenate

返回:

docs_cat =

The quick brown fox jumped over the lazy dog. 

关于arrays - 使用 for 循环连接多个元胞数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21767830/

相关文章:

string - 如何从 std::borrow::Cow<str> 获取 &str 或 String?

数组中的 PHP 变量

arrays - Swift:数组引用作为对象属性?

java - 数组困惑

matlab - 避免逻辑挤压函数中的无穷大

python - Pandas concat 生产 NaN

c - 在c中使用char数组实现一个64 block 逻辑磁盘

matlab - 清除图像中的噪声

c++ - 与 matlab 相比,获得正确的三角函数值

预连接的 PHP 速记?