I have an array of 100K structs. I am listing below the contents of one such struct:
Iteration:1
BlockID:86
The BlockID can have values between 1 and 100. I want to find out the count of occurrences of BlockID. For eg.: BlockID “1” occurred 25 times; BlockID “98” occurred 58 times and so on.
I looked online and tried the options mentioned in these links, but could not get a solution:
Matlab: Count number of structs that have a specific content
how to count unique elements of a cell in matlab?
Matlab: How to calculate how many unique strings are stored in the cell?
You can use
arrayfunandcount_unique(count_unique is not an official function – it’s from the matlab central file exchange and can be found here):NB: As pointed out by rody_o (though he/she missed the fact that the indexing is unnecessary) there is an alternative way to concatenate the, ids, namely
Alternatively you could create your own
count_uniquefunction if you wished,