Storing values form a while loop within a for loop.
Afficher commentaires plus anciens
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?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!