MATLAB: How to randomly divide the data

datadatasampleindexrandom

I have a matrix X with size nxm, How I can choose randomly 70 percent of this data and put it in matrix A and the rest in matrix B. I have already selected the 70% (according to rows) using the 'datasample' function, is there any tip to select the rest 30% of the data with there indices
[n,m]=size(X);
[A,idx] = datasample(X,round(0.7*n));
Thanks in advance for your help

Best Answer

[A, idxA] = datasample(X, round(0.7*n));
idxB = 1:n;
idxB(idxA) = [];
B = X(idxB);
This is slightly faster than:
idxB = setdiff(1:n, idxA);