randperm

Illustration
krastinedekart13 - 2022-07-26T23:12:07+00:00
Question: randperm

How can I use randperm for a nx2 matrix?

Expert Answer

Profile picture of John Williams John Williams answered . 2025-11-20

"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)
 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!