Hi i want to know if i have a specific numbers like (5 9 11) and i want to distribute them randomly on array which i know it's size , How can i do that?
1 view (last 30 days)
Show older comments
Hi i want to know if i have a specific numbers like (5 9 11) and i want to distribute them randomly on array which i know it's size , How can i do that?
0 Comments
Answers (2)
Andrei Bobrov
on 14 Dec 2015
k = [5 9 11];
ii = randi([1,3],10,6); % [10,6] - size of your array
out = k(ii);
Walter Roberson
on 14 Dec 2015
Otherwise:
specific_numbers = [5, 9, 11];
array_size = [48,93]; %for example
rand_array = specific_numbers( randi(length(specific_numbers), array_size) );
This presumes equal probability for the samples.
0 Comments
See Also
Categories
Find more on Random Number Generation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!