how can slect randomly numbers from two array s
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
usman younus
am 28 Jun. 2017
Beantwortet: Gopichandh Danala
am 28 Jun. 2017
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 Kommentar
Akzeptierte Antwort
Gopichandh Danala
am 28 Jun. 2017
A=[3818.36,7632.40,11446.44,15260.48,19074.52];
B=[657.15,1089.15,1521.15,1953.15,2385.15];
vals = zeros(1,length(A));
for i = 1:length(A)
idx = randperm(2,1);
if idx == 1
vals(i) = A(i);
else
vals(i) = B(i);
end
end
disp(vals)
0 Kommentare
Weitere Antworten (2)
Andrei Bobrov
am 28 Jun. 2017
Bearbeitet: Andrei Bobrov
am 28 Jun. 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));
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!