I have a matrix like:
A= 4 7 8 9 3 3 5 7 6 4 8 6
and wants to random shuffle columns and do it something like:
A= 8 4 9 7 5 3 7 3 8 6 6 4
does anyone have any idea?
randperm(n) returns a row vector that contains a random permutation of the integers from “1” to “n” without of any repetition. randperm(n,k) returns a row vector that contains “k” number of unique integers that are selected randomly from 1 to n.
Use the rand , randn , and randi functions to create sequences of pseudorandom numbers, and the randperm function to create a vector of randomly permuted integers. Use the rng function to control the repeatability of your results.
p = randperm( n ) returns a row vector containing a random permutation of the integers from 1 to n without repeating elements.
You can shuffle columns using indexing:
A(:,[3 1 4 2])
If you want to do it randomly, you can create a random permutation:
A(:,randperm(size(A,2)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With