在Matlab中迭代唯一值

在Matlab中迭代唯一值,matlab,text,brackets,curly-braces,word-frequency,Matlab,Text,Brackets,Curly Braces,Word Frequency,为了从给定的单元格数组中获得唯一的字符串,我一直在尝试跟随。然而,在迭代这些值时,我遇到了麻烦。我尝试了如下循环: [unique_words, ~, occurrences] = unique(words); unique_counts = hist(occurrences, 1:max(occurrences)); for a=1:numel(unique_words) word = unique_words{a} count = unique_counts{a} result

为了从给定的单元格数组中获得唯一的字符串,我一直在尝试跟随。然而,在迭代这些值时,我遇到了麻烦。我尝试了如下循环:

[unique_words, ~, occurrences] = unique(words);
unique_counts = hist(occurrences, 1:max(occurrences));

for a=1:numel(unique_words)
  word = unique_words{a}
  count = unique_counts{a}
  result = result + a_struct.(unique_words{a}) + unique_counts{a}
end
当尝试引用以下项目时,我收到错误:

来自非单元格数组对象的单元格内容引用

unique\u couts
的花括号更改为圆括号会产生错误:

对不存在字段“N1”的引用

unique_单词
unique_计数
更改为圆括号将产生:

动态结构引用的参数必须计算为有效的字段名


如何迭代unique的结果?

unique\u words
是一个单元格数组<代码>唯一计数是一个向量。因此,
unique_单词
应使用花括号访问,而
unique_计数
应使用圆括号访问。本例中出现的错误与
a_struct
(问题中未定义)没有相应字段,而不是访问方法有关

unique\u words
是一个单元格数组<代码>唯一计数是一个向量。因此,
unique_单词
应使用花括号访问,而
unique_计数
应使用圆括号访问。本例中出现的错误与
a_struct
(问题中未定义)没有相应字段,而不是访问方法有关

unique\u words
是一个单元格数组<代码>唯一计数是一个向量。因此,
unique_单词
应使用花括号访问,而
unique_计数
应使用圆括号访问。本例中出现的错误与
a_struct
(问题中未定义)没有相应字段,而不是访问方法有关

unique\u words
是一个单元格数组<代码>唯一计数是一个向量。因此,
unique_单词
应使用花括号访问,而
unique_计数
应使用圆括号访问。本例中出现的错误与
a_struct
(问题中未定义)没有相应字段,而不是访问方法有关