Need help creating an matrix that includes probability
Mostra commenti meno recenti
So i am asked to make an matrix that is 96x96. this matrix must have a 5% probability of getting a 0 instead of a 1. i know that when creating the matrix i can write
matrix= ones (96,96)
i just dont know how to implement the random generating
Risposta accettata
Più risposte (1)
Ajay Kumar
il 8 Ott 2019
r = randi([0 1],96,96);
zero_count = round(0.05*numel(r));
count = 0;
for i = 1 : 96
for j = 1: 96
if r(i,j) == 0
count = count+1;
if count > zero_count
r(i,j) = 1;
else
end
end
end
end
1 Commento
the cyclist
il 8 Ott 2019
I assume Raul meant that each matrix element has a 5% chance of being zero. This method will not yield that.
Categorie
Scopri di più su Random Number Generation in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!