MATLAB: How to select random rows from a matrix and delete it from the original matrix for another random selection.

matrixrandsample

This piece of code below select random rows from a matrix without replacement. How can I adjust this code to delete the data selected from the original matrix. What I want to achieve is to randomly split a large dataset into six and randomly selects it data from the original matrix. Any kind of help is appreciated.
index = randsample(1:length(X), 10);
X1 = X(index,:);

Best Answer

A=rand(100); % a random matrix
n=10;.
idx=randsample(1:size(A,1),n) ;
B = A(idx,:) ; % pick rows randomly
A(idx,:)=[]; % remove those rows
idx = randsample(1:size(A,1),n) ;
C= A(idx,:);
Related Question