Finding number of answers from for loop that fits criteria

조회 수: 2 (최근 30일)
Cside
Cside 2019년 11월 28일
댓글: JESUS DAVID ARIZA ROYETH 2019년 11월 28일
Hi, currently I have a code that looks something like this and would like the answer to be the number of p that fit the criteria of < 0.05. However, it does not seem to work as the for loop does not collate the p values that runs through the loop i.e. the answer will be over-written with each loop. Is there a way I can better write this? Thank you!
for n = 1:30
p = anova1(A(n,:), locations', 'off');
end
ans = sum(p<0.05)

채택된 답변

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019년 11월 28일
solution:
p=zeros(1,30);
for n = 1:30
p(n) = anova1(A(n,:), locations', 'off');
end
anss = sum(p<0.05)
  댓글 수: 3
JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019년 11월 28일
Maybe it's really 0, try this one:
anss=0;
for n = 1:30
p= anova1(A(n,:), locations', 'off');
anss=anss+(p<0.05);
end
disp(anss)
Cside
Cside 2019년 11월 28일
thank you jesus david :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by