我是matlab的新手。作为更大问题的一部分,我需要在字符串数组中找到最大数量的字符串。java到matlab的转换
由于我在java中有一些经验,我已经用java编写了部分代码(只有当字符串数组中字符串的出现次数可以计算出来时,我才可以根据这些值对这个hashmap进行排序并解压缩)
int incr = 0;
String[] c = { "c1", "c2", "c3", "c1", "c2", "c2", "c2","c1","c2" };
Map<String, Integer> classRegistry = new HashMap<String, Integer>();
for (int i = 0; i < c.length; i++) {
String classes = c[i];
if (!(classRegistry.containsKey(classes))) {
for (int j = i + 1; j < c.length; j++) {
if (classes.equals(c[j])) {
incr++;
}
}
classRegistry.put(classes, incr+1);
incr = 0;
}
}
任何想法如何,我可以使用像MATLAB中的一个HashMap来计算阵列中的所有串出现的次数
感谢,
巴维亚
我使用了列表功能,很容易获得解决方案。 – bhavs