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

조회 수: 1 (최근 30일)
Daniel
Daniel 2015년 5월 19일
댓글: Daniel 2015년 5월 19일
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