Making a matrix of R*C size that takes the values randomly from an array- Y.
Show older comments
I want to make a random matrix of R*C size that takes the values randomly from an array Y.
For example I want to make a 7*8 matrix that takes value from this array Y = [ 1 6 1 8 4 5], and place them randomly in the matrix.. I have tried randi command to do this, but randi doesn't take fixed values like I have stated above.
Accepted Answer
More Answers (1)
i1 = 7; i2 = 8;
y = [1 6 1 8 4 5];
randIdx = randi(length(y), 1, i1*i2);
data = reshape(y(randIdx), i1, i2)
1 Comment
MAzharul Islam
on 18 Aug 2021
Categories
Find more on Logical 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!