How can I generate three random matrices from 20 percent of the rows of a 2000 by 80 matrix, using for loop?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
DGM
le 24 Juin 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 commentaires
Plus de réponses (1)
Chunru
le 24 Juin 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 commentaires
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!