i want to fill matrix with some numbers

1 view (last 30 days)
Mohamed Ayman
Mohamed Ayman on 29 Oct 2019
Commented: the cyclist on 29 Oct 2019
i have some numbers (50,90,60,73,55,96,47,63,555,46,756,968,453,452,500) i want to distribute this numbers randomly in a matrix(80000,5)
  1 Comment
the cyclist
the cyclist on 29 Oct 2019
Do you mean that the entire matrix should be filled with those values, chosen at random, or you want a matrix of zeros, with only 15 spots chosen at random, with those values?

Sign in to comment.

Answers (2)

Star Strider
Star Strider on 29 Oct 2019
Try this:
SomeNumbers = [50,90,60,73,55,96,47,63,555,46,756,968,453,452,500];
idx = randi(15, 8000, 5);
RandMatrix = SomeNumbers(idx);
Check = RandMatrix(1:5, 1:5) % Sample Output (Delete Later)
producing (in this run):
Check =
555 60 968 453 96
90 73 968 452 55
756 500 60 555 60
55 96 73 47 60
452 50 453 60 46
  1 Comment
the cyclist
the cyclist on 29 Oct 2019
This corresponds to the first option in my comment/question above.

Sign in to comment.


the cyclist
the cyclist on 29 Oct 2019
Edited: the cyclist on 29 Oct 2019
If you have the Statistics and Machine Learning Toolbox:
% Inputs
v = [50,90,60,73,55,96,47,63,555,46,756,968,453,452,500];
M = zeros(80000,5);
% Generate unique random indices
idx = randsample(numel(M),numel(v));
% Fill in the matrix. (Uses linear indexing)
M(idx) = v;
(This corresponds to the second option in my comment/question above.)

Products


Release

R2015a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!