MATLAB Answers

Finding number of answers from for loop that fits criteria

4 views (last 30 days)
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)

  0 Comments

Sign in to comment.

Accepted Answer

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH on 28 Nov 2019
solution:
p=zeros(1,30);
for n = 1:30
p(n) = anova1(A(n,:), locations', 'off');
end
anss = sum(p<0.05)

  3 Comments

Charms
Charms on 28 Nov 2019
the answer is 0 :( May I know what the significance of the first line of code?
JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH on 28 Nov 2019
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)

Sign in to comment.

More Answers (0)