Random order of rows Matlab

edgarmtze picture edgarmtze · Mar 26, 2011 · Viewed 47.1k times · Source

Say we have a matrix of size 100x3

How would you shuffle the rows in MATLAB?

Answer

Jonas picture Jonas · Mar 26, 2011

To shuffle the rows of a matrix, you can use RANDPERM

shuffledArray = orderedArray(randperm(size(orderedArray,1)),:);

randperm will generate a list of N random values and sort them, returning the second output of sort as result.