Create 9x9 matrix with RANDI between [0,2] with each 0,1, and 2 repeating three times each per column.
Show older comments
I'm trying to create a 9x9 matrix with random number generation from 0 to 2 using RANDI:
X = randi([0,2], 9,9)
However, I want to force each of the 9 columns to show an equal distribution of 0's, 1's, and 2's (3 x of each number per column). I'm having difficulty finding a loop that can do this. Any help would be great (very new to this type of MATLAB work).
Thanks.
Accepted Answer
More Answers (1)
Bruno Luong
on 23 Sep 2020
Edited: Bruno Luong
on 23 Sep 2020
[~,A] = sort(rand(9)); A = mod(A,3)
Categories
Find more on Random Number Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!