Calculate a mean if two statements are true
Mostrar comentarios más antiguos
I have a matrix that has several rows and columns of data. I am trying to get a mean from all the values of row 6 but only if row 5 = 1 and row 7 = 0. Initially to calculate mean of row 6 if row 5 = 1 I used this:
mean(cellm(6,logical(cellm(5,:))));
Now I would like to add the second portion where row 7 = 0. I have attempted this with the code below:
mean(cellm(6,(find(cellm(7,:) < 1) & (logical(cellm(5,:))))))
But I get the error "Inputs must have the same size.
Any suggestions would be appreciated.
Here is an example of the matrix below:
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
4 0 0 0 0 4 4 0 0 0
11 11 11 11 11 22 22 11 11 11
0 1 1 1 1 1 1 1 1 1
1200 1700 1400 1800 1800 417 603 1700 1600 1700
0 1 1 1 1 0 0 1 1 1
1 1 1 1 1 2 2 1 1 1
1 0 0 0 0 0 0 0 0 0
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Data Type Identification en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!