Summing up the answers in for loop that meets criteria

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Gifari Zulkarnaen
Gifari Zulkarnaen il 15 Feb 2020
Modificato: Gifari Zulkarnaen il 15 Feb 2020
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);

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by