3
votes

Lets say that I have a number of n matrices with the same size (p x q elements). Can you obtain a matrix contains the elements with the highest frequency on each corresponding position?

For example, let's say that I have 3 matrices with 3 x 3 elements:

m1 = [1 0 0; 0 2 0; 0 2 0]
m2 = [1 0 0; 0 2 0; 0 3 0]
m3 = [1 0 0; 0 0 0; 0 3 0]

The resulting matrix should be:

 m = [1 0 0; 0 2 0; 0 3 0]

I have done this by going through each position of my matrices, but in my real case I have 1000 x 1000 and it would take too long. Is there an automated way of doing this?

1

1 Answers

8
votes

Firstly, you should combine everything into a 3D array; that will be much easier to handle than loads of individually-named 2D arrays.

Once you have done that, you can simply do mode(m_everything, 3).