I am a newbie at matlab . As a part of a larger problem, I need to find maximum number of occurrences of a string in an array of Strings.
Since I have some experience in java I have written the partial code in java ( only until the number of occurences of the string within the string array can be computed I can sort the hashmap depending on the values and extract this)
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;
}
}
Any idea how i can use something like a hashMap in MATLAB to calculate the number of occurrences of all the strings in an array
Thanks,
Bhavya