Storing values form a while loop within a for loop.
古いコメントを表示
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?
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!