How to generate random indicies?
2 views (last 30 days)
Show older comments
I would like to generate k different random indices from 1 to N. One solution is randperm(N,k), however I do not need to shuffle the indicies. Are there any other solution directly generating idicies in order?
0 Comments
Answers (2)
Image Analyst
on 31 Jan 2015
Edited: Image Analyst
on 31 Jan 2015
Yes, but if they're not "shuffled" then they're not random, are they? So you can get indices in ascending numerical order from 1 to N this way:
indices = 1 : N;
If you want what you said, but just sorted , then sort them:
pseudoRandomIndices = sort(randperm(N, k), 'ascend');
4 Comments
Image Analyst
on 1 Feb 2015
We're not sure which algorithm you're thinking of, sort or randperms, but feel free to rewrite either one with a less complicated version of them. We're not going to do that for you. Good luck.
See Also
Categories
Find more on Shifting and Sorting Matrices 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!