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

1 次查看(过去 30 天)
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

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by