How to shuffle (completely at random) big data stored in Excel file by Matlab?

StackOverflow https://stackoverflow.com/questions/16331159

  •  14-04-2022
  •  | 
  •  

سؤال

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

هل كانت مفيدة؟

المحلول

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)), :)

نصائح أخرى

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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top