Creating a matrix with three different values with different probability.
Afficher commentaires plus anciens
I'm trying to generate a matrix
with three distinct values
with each probability 1/6 and 0 with probability 2/3.
- I'm trying to approach this problem by creating a first vector with 25 elements with
, second vector with 25 elements with
, third vector with 100 elements with 0. - I will use horzcat to create a vector of
. - Then I reshuffle the vector using randperm.
- Finally, I will use reshape to convert vector into a matrix of
.
I would like to know whether this approach is correct. If it is correct, is there any other better approach to solve this problem ?
c1= sqrt(3)*ones(1,25);
c2= -sqrt(3)*ones(1,25);
c3= zeros(1,100);
c = horzcat(c1, c2, c3)
d = c(randperm(length(c)));
T = reshape(d, 10, 15);
Many thanks for this wonderful community.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Random Number Generation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!