randperm

K
krastinedekart13 · Jul 26, 2022 · 2.1K views
Question
How can I use randperm for a nx2 matrix?
Expert Answer
Profile picture of John Williams
John Williams PhD Expert
Answered Aug 17, 2026

"randperm" only takes 1 scalar input argument. Can you give a sample of an input nx2 matrix AND what you would expect the output to be?

If you want to randomly permute the rows, do something like the following.

n = 5;
A = reshape(1:2*n, n, 2)
B = A(randperm(n), :)
if you want to randomly permute all elements, do something like this instead.
C = reshape(A(randperm(2*n)), n, 2)
 
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!