How can I generate three random matrices from 20 percent of the rows of a 2000 by 80 matrix, using for loop?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuesta aceptada
DGM
el 24 de Jun. de 2021
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),:);
0 comentarios
Más respuestas (1)
Chunru
el 24 de Jun. de 2021
a = magic(20);
for i = 1:3
idx = randperm(20, 4); % 4 is 20% of 20; for your case 2000*20%
b = a(idx, :)
end
0 comentarios
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!