How to generate a vector of two separate intervals without overlapping?

1 Ansicht (letzte 30 Tage)
Assume that we have two vectors:
a = 1 2 3 4 5
b= 6 7 8 9 10
how can I generate a vector of random permutation of combining a and b so I can always get random permutation of a at first and then random permutation of b in vector c as below:
c = 1 2 3 4 5 6 7 8 9 10
or
c = 5 1 3 4 2 9 7 6 10 8

Akzeptierte Antwort

Bruno Luong
Bruno Luong am 6 Nov. 2018
c = [a(randperm(length(a))) b(randperm(length(b)))]
  3 Kommentare
Hajem Daham
Hajem Daham am 6 Nov. 2018
What if I need to mix c form a followed always by number/s from b, in this case c should be as:
c = a b a b a b
for example
c = 1 2 6 7 3 4 8 5 9 10
and so on.
Thanks

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Random Number Generation 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!

Translated by