Mean of values in the 1st column where the value in the second column is zero
Show older comments
I have data in a MAT file with 2 columns, the first column is length and the second column is 0 or 1.
eg: Length Y/N
2.5 1
3.2 0
How do I get mean of all values of first column where the value in second column is zero?
Answers (3)
Azzi Abdelmalek
on 28 Feb 2014
Edited: Azzi Abdelmalek
on 28 Feb 2014
M=[2.5 1;3.2 0]
c1=M(:,1)
c2=M(:,2)
idx=c2==0
out=mean(c1(idx))
Star Strider
on 1 Mar 2014
In one line:
S = mean(M(M(:,2)==0),1)
Sid
on 1 Mar 2014
0 votes
Categories
Find more on Whos 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!