How can i use randperm without involving some certain numbers?
2 views (last 30 days)
Show older comments
For example i want to use randperm(5,3). But it should not include number 2. It can take any 3 values from 1 to 5, without including number 2.
0 Comments
Accepted Answer
Guillaume
on 22 Jun 2015
Edited: Guillaume
on 22 Jun 2015
Use randperm to compute a random permutation of indices into your value instead of a random permutation of your values:
values = [1 3 4 5]
randidx = randperm(numel(values));
randvalues = values(randidx)
%or as one line:
randvalues = values(randperm(numel(values)))
0 Comments
More Answers (0)
See Also
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!