Generate a loop vector with certain probability?

1 回表示 (過去 30 日間)
pauldjn
pauldjn 2018 年 9 月 26 日
編集済み: pauldjn 2018 年 9 月 26 日
Hi, I have this loop to generate a matrix of size d with the numbers 1,2,3,4 according to a certain frequency (fn...) and each time one of the elements of the matrix is generated the frequency is recalculated but only after all the numbers generated in each g{x} has been completed. So actually the recalculated frequency is not completely accurate, can be a different way to calculate it not for the whole set but after each number is generated?
d= poissrnd(lambda,1,1000);
for x = 1:numel(d)
tot= q1 + q2 + q3 + q4
f1= q1 / tot
f2= q1 / tot
f3= q1 / tot
f4= q1 / tot
g{x} = randsrc(1,d(x),[1,2,3,4;f1,f2,f3,f4]);
f1 = f1 - (sum(d{x}==1));
f2 = f2 - (sum(d{x}==2));
f3 = f3 - (sum(d{x}==3));
f4 = f4 - (sum(d{x}==4));
end

回答 (0 件)

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by