Summing up the answers in for loop that meets criteria

조회 수: 1 (최근 30일)
Cside
Cside 2020년 2월 15일
편집: Gifari Zulkarnaen 2020년 2월 15일
I have this code and would like to find out of the 220 loops, how many of the corrcoef end answer fit the criteria of P<0.05 and r >0.3. I want the the loop to reflect the sum of all the corrcoef values that fit the criteria, and not for every loop. Thank you for the help!
for n = 1:220
pfc = A(combi(n,1),1:270);
fef = B(combi(n,2),1:270);
zpfc = zscore(pfc);
zfef = zscore(fef);
[R,P] = corrcoef(zpfc,zfef);
sum(P(2,1) <0.05 & R (2,1) > 0.3); %%(2,1) being the position of the value in the 2x2 corrcoef output
end

채택된 답변

Gifari Zulkarnaen
Gifari Zulkarnaen 2020년 2월 15일
편집: Gifari Zulkarnaen 2020년 2월 15일
Try this
criteria=zeros(220,1)
for n = 1:220
pfc = A(combi(n,1),1:270);
fef = B(combi(n,2),1:270);
zpfc = zscore(pfc);
zfef = zscore(fef);
[R,P] = corrcoef(zpfc,zfef);
criteria(n) = P(2,1)<0.05 & R(2,1)>0.3; %%(2,1) being the position of the value in the 2x2 corrcoef output
end
your_answer = sum(criteria);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by