Summing up counts in multiple matrices

Hi all, complete newbie to matlab!
I have 15 matrices each with 2 rows and 100 columns. I need to count the number of values equal to or greater than 3 in each column for each row in each matrix (i.e. how many of the 100 columns contain values greater than or equal to 3) and then combine those counts in a single matrix for all 15.
A more manageable example:
If I have 3 matrices:
A = [2 3 9 6 5; 5 4 8 10 11]
B = [8 9 5 6 7; 2 1 5 9 4]
C = [ 1 3 2 6 8; 3 1 4 5 7]
How many columns have values equals or greater than 3?
A = [5;5] B = [5;4] and C = [3;4]
Final matrix = [5,5,3; 5,4,4]
Thanks!

1 comentario

Stephen23
Stephen23 el 25 de Oct. de 2017
Editada: Stephen23 el 25 de Oct. de 2017
"I have 15 matrices ..."
And that is the start of making this problem difficult to solve. If you had simply stored yoru data in one ND array or one cell array, then your task could be solved trivially using simple vectorized code or a loop.
By deciding to have lots of separate variables, you make your code more complex, and solving this problem much harder.

Iniciar sesión para comentar.

Respuestas (2)

KSSV
KSSV el 25 de Oct. de 2017
A = [2 3 9 6 5; 5 4 8 10 11]
B = [8 9 5 6 7; 2 1 5 9 4]
C = [ 1 3 2 6 8; 3 1 4 5 7]
A = sum(A>=3,2) ;
B = sum(B>=3,2) ;
C = sum(C>=3,2) ;
[A B C]

Categorías

Preguntada:

el 25 de Oct. de 2017

Respondida:

el 25 de Oct. de 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by