我有一个包含 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/