Generate a loop vector with certain probability?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!