Reputation: 1366
I have a matrix:
A = [1;2;3;4];
I would like to create another matrix B of size 20*1 from A. How can I implement that effectively? Elements can be repeated and should be picked in random order.
Upvotes: 2
Views: 208
Reputation: 74940
For the general case, where the elements of A can take any value, you can use randsample
(you can even set different probabilities for each element).
B = randsample(A(:),20);
Upvotes: 3