Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab - Voting matrix

Tags:

matlab

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?

like image 981
Simon Avatar asked Jan 28 '26 02:01

Simon


1 Answers

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).

like image 93
Oliver Charlesworth Avatar answered Jan 31 '26 06:01

Oliver Charlesworth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!