How do I select data from one vector based upon the values of another vector?

I am attempting to select data from a vector v() based upon another vector, s(). These vectors are already ordered based upon participant, i.e., the first element in vector v() and vector s() are from the same participant, the second element in both are from the same participant, etc.
Vector s() is a binary value (sex). I am attempting to select all participants who are male from vector v() to determine the mean of these data. How can I go about accomplishing this?

 채택된 답변

jonas
jonas 2018년 10월 4일
편집: jonas 2018년 10월 4일
mean(v(s==true))
And false for the opposite gender
If you have more complex grouping data, then
G = findgroups(s)
splitapply(@mean, v, G)
Or put the data in a table and use grpstats

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2018년 10월 4일

댓글:

2018년 10월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by