I have a cell in MATLAB where each element contains a vector of a different length
e.g.
C = {[1 2 3], [2 4 5 6], [1 2 3], [6 4], [7 6 4 3], [4 6], [6 4]}
As you can see, some of the the vectors are repeated, others are unique.
I want to count the number of times each vector occurs and return the count such that I can populate a table in a GUI where each row is a unique combination and the date shows how many times each combination occurs.
e.g.
Count
"[1 2 3]" 2
"[6 4]" 2
"[2 4 5 6]" 1
"[7 6 4 3]" 1
"[4 6]" 1
I should say that the order of the numbers in each vector is important i.e. [6 4] is not the same as [4 6].
Any thoughts how I can do this fairly efficiently?
Thanks to people who have commented so far. As @Divakar kindly pointed out, I forgot to mention that the values in the vector can be more than one digit long. i.e. [46, 36 28]
. My original code would concatenate the vector [1 2 3 4]
into 1234
then use hist to do the counting. Of course this falls apart when you got above single digits as you can tell the difference between [1, 2, 3, 4]
and [12, 34]
.