Question

I want to shuffle my data row wise (in a single unique row there will be no shuffling, it has to remain the same - I mean all individual cells in a single row can not change). The number of rows I have in my excel files is around 170000.

All I need is to shuffle randomly all the rows among them. How can I do this by mat-lab commands? Codes or algorithm please!

enter image description here

Was it helpful?

Solution

For reading and writing excel files see xlsread and xlswrite.

To randomly shuffle the rows of a matrix:

M = magic(5);
Mshuffled = M(randperm(size(M, 1)), :)

OTHER TIPS

As mentioned by @Dan, you can use xlsread and xlswrite for manipulation of Excel files. You could use randperm to achieve shuffling effectively, but another way to achieve this would be using the randsample command.

For example:

>> A = randint (5,2,[1,10])

A =

     2     2
    10     5
    10    10
     5     8
     9    10

>> A(randsample(1:size(A,1),size(A,1)),:)

ans =

    10     5
     2     2
     9    10
    10    10
     5     8
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top