【发布时间】:2015-05-08 08:29:58
【问题描述】:
我一直在尝试关注this answer,以便从给定的元胞数组中获取唯一的字符串。但是,在迭代这些值时我遇到了麻烦。我尝试了如下循环:
[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_couts 的大括号更改为圆括号会产生错误:
引用不存在的字段“N1”。
将unique_words 和unique_counts 都更改为圆括号会产生:
动态结构引用的参数必须评估为有效的字段名称。
我如何迭代 unique 的结果?
【问题讨论】:
标签: matlab text brackets curly-braces word-frequency