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!