Question
How can I use randperm for a nx2 matrix?
Related Questions
Expert Answer
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