MATLAB: How to generate three random matrices from 20 percent of the rows of a 2000 by 80 matrix, using for loop

for loopindexingmatricespercentrandom

Let's X=[2000 by 80]. Now I want to get X1, X2 and X3 randomly from X. Each matrix is 20 percent of the X.
Please help me out.
Thank you

Best Answer

I don't see why a loop is necessary. Is it?
A = rand(2000,80); % test array
s = size(A,1);
nrows = round(s*0.2);
X1 = A(randperm(s,nrows),:);
X2 = A(randperm(s,nrows),:);
X3 = A(randperm(s,nrows),:);