我是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