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 CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by