Summing up the answers in for loop that meets criteria
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!