Calculate a mean if one statement is true for a previous row

3 visualizaciones (últimos 30 días)
Daniel
Daniel el 19 de Mayo de 2015
Comentada: Daniel el 19 de Mayo de 2015
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 data is only included if row 5 = 0 in the previous column of data.
OverallM = mean(cellm(6,~(cellm(5,:))));
For example the code above will give me my mean for row 6 if row 5 has a 0 for the same column as row 6. How would I modify this so that it would give me my mean if row 5 has a 0 for the previous column.
Here is an example of my data format.
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 0 1 1 1 1 1 0 1
357 567 267 800 927 417 603 564 765 488
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
In the case above I would want the mean of 567, 800, and 488 because row 5 in the previous column was a 0.
Any suggestions would be appreciated.
Thank you

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 19 de Mayo de 2015
out = mean(cellm(6,strfind(cellm(5,:),[0, 1])+1));

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by