How do I create a matrix with a randomized permutation of integers?

Alternatively: What is the matrix equivalent of randperm(n,k)?
I can't figure out a simple way to do this.

 Accepted Answer

Can you accomplish what you want by simply reshaping a random vector into a matrix?
reshape(randperm(16,16),[4,4])
ans =
4 12 11 15
7 5 13 9
14 8 2 1
6 10 3 16

1 Comment

Yes, this is just the thing I need! I never knew there was such a function, thank you :)

Sign in to comment.

More Answers (0)

Categories

Find more on Strategy & Logic 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!