How to do the mean with a condition?

1 view (last 30 days)
ProjectVOC
ProjectVOC on 4 Nov 2013
Edited: Matt J on 4 Nov 2013
Hello,
Here is my problem, i have a huge matrix. And i have to do the mean for a row but only with a condition, i created a logical vector which contain 1 when i want to include the value and 0 when i don't.
For example
A=
[2 3 4 5 0
6 7 8 9 1
7 5 1 2 1
2 5 6 9 0]
And i want the mean for the second column when the 4th have a value of 1, so mean=6.
Thanks for your help :)
  4 Comments
Image Analyst
Image Analyst on 4 Nov 2013
I guess I'll leave it to someone who is still not confused by what you're saying to answer.
ProjectVOC
ProjectVOC on 4 Nov 2013
Sorry, english isn't my mother tongue.
I find a solution with a loop, not very elegant but fine for the moment.
Thanks for your time.

Sign in to comment.

Answers (1)

Matt J
Matt J on 4 Nov 2013
Edited: Matt J on 4 Nov 2013
mean(A(logicalVector,:),1)

Tags

Community Treasure Hunt

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

Start Hunting!