Mean based on positive and negative values of a field

조회 수: 9(최근 30일)
SS
SS 2019년 8월 29일
댓글: SS 2019년 8월 30일
I have a structure S (10000 X 1) with 10 fields. I want to calculate (two) means and standard deviations of one particluar field f1. I have condition on field f2.
mean_1 and SD_1: consider the values of f1 (in calculation of mean and SD) if, f2 is positive.
mean_2 and SD_2: consider the values of f1 (in calculation of mean and SD) if, f2 is negative.
Any smart way to do this?

채택된 답변

Rik
Rik 2019년 8월 29일
Logical indexing:
L=[S.f2]>0;
pos_mean=mean([S( L).f1]);
neg_mean=mean([S(~L).f1]);
  댓글 수: 7
SS
SS 2019년 8월 30일
Great, thanks.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

범주

Find more on Matrices and Arrays 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!

Translated by