Search code examples
matlabmode

How to find multiple modes in an array


I have an array [1 1 1 2 3 4 5] for which the mode is 1. However, in the array [1 1 2 2 3 4 5] there is no mode since the number of 1's and 2's is equal.

Is there a way to say that both are the modes using Matlab? Such that for the first example the mode is 1, but for the second example the modes are 1 and 2?


Solution

  • This is what the third output of mode does:

    >> [~,~,C] = mode([1 1 2 2 3 4 5])
    C =
    {
      [1,1] =
    
         1
         2
    
    }