how can slect randomly numbers from two array s
Afficher commentaires plus anciens
A=[3818.36,7632.40,11446.44,15260.48,19074.52];
B=[657.15,1089.15,1521.15,1953.15,2385.15];
I have two arrays with 5 elements each and want to select 5 numbers randomly from both arrays, please help me how can select any 5 number from both A & B
1 commentaire
Jan
le 28 Juin 2017
With repetitions or without?
Réponse acceptée
Plus de réponses (2)
idx = randperm(10,5);
C = [A, B];
selectedNums = C(idx);
or to be a little more generic and avoid ugly hard-coded numbers that can be taken from the data instead:
C = [A, B];
idx = randperm(numel(C),5);
selectedNums = C(idx);
1 commentaire
usman younus
le 28 Juin 2017
Andrei Bobrov
le 28 Juin 2017
Modifié(e) : Andrei Bobrov
le 28 Juin 2017
A=[3818.36,7632.40,11446.44,15260.48,19074.52];
B=[657.15,1089.15,1521.15,1953.15,2385.15];
C = [A;B];
out = C(sub2ind(size(C),randi([1,2],1,5),1:5));
Catégories
En savoir plus sur Elementary Math dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!