How to generate two subsets randomly from a matrix without repetition?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Federico Frics
le 13 Avr 2015
Modifié(e) : Mohammad Abouali
le 13 Avr 2015
Hi everyone,
I need to know that how can I generate 2 subsets randomly from a matrix? For example, my reference matrix is 10*1, and I'm going to generate 2 matrix with 4*1 and 6*1, without any repetition of the arrays in both the subsets. I'm aware about 'Randperm' and generation the first subset using that, but when I need to generate the second subset, I'm not able to extract remained arrays from the matrix and to incorporate the second subset!numerically, I want something like the following:
A=[1 3 5 6 2 4 7 ]; % The reference matrix
b=[5 3 4 1]; % Subset 1
c=[1 7 6 5]; % Subset 2
Thanks
0 commentaires
Réponse acceptée
Mohammad Abouali
le 13 Avr 2015
Modifié(e) : Mohammad Abouali
le 13 Avr 2015
So we have matrix A with 10 elements. We want to randomly divide it into two non-overlapping subset, one with 4 elements another with 6. Here is one solution
A=[1 3 5 6 2 4 7 8 9 0];
idx=randperm(numel(A))
subSet1=A(idx(1:4))
subSet1 =
9 6 0 7
subSet2=A(idx(5:end))
subSet2 =
1 8 4 3 5 2
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrices and Arrays 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!