Calculate a mean if one statement is true for a previous row
2 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!