Storing values form a while loop within a for loop.
Show older comments
Hi, I've tried to run a while loop a hundred times with a for loop. My goal is to store the counting variable (k) from each while-loop In a vector, and then take the mean of this vector. I've coded it this way;
Q = zeros(1,100);
for (ii) = 1 : 100
k = 0 ; %counting variabel
sum = 0;
critical_value = 1.9;
while sum<critical_value
sum = rand(1) + rand(1) ;
k = k + 1;
end
Q(1,k) = k;
end
W = mean(Q(1,k));
My problem is that the values I try to store don´t really make sense compared to what I intended it to be. The end goal of this project is to test the mean of the stored counting variables against an predetermined expected value.
Do anyone have a suggestion on how to solve my problem?
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!