我在Matlab中有一个大的字符串数组.我需要在这个数组中找到重复字符串的索引.也就是说,我期望的输出是在字符串的单元格数组中出现两次或更多次的字符串索引的数组.
我怎样才能做到这一点?
这是可以做到的独特的:
strings = {'some' 'strings' 'with' 'with' 'duplicate' 'strings' 'strings'};
[~, uniqueIdx] =unique(strings) % Find the indices of the unique strings
duplicates = strings % Copy the original into a duplicate array
duplicates(uniqueIdx) = [] % remove the unique strings, anything left is a duplicate
duplicates = unique(duplicates) % find the unique duplicates
Run Code Online (Sandbox Code Playgroud)