How can I generate three random matrices from 20 percent of the rows of a 2000 by 80 matrix, using for loop?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
DGM
il 24 Giu 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 Commenti
Più risposte (1)
Chunru
il 24 Giu 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 Commenti
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!