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

2 ビュー (過去 30 日間)
Hajem Daham
Hajem Daham 2018 年 11 月 6 日
コメント済み: Bruno Luong 2018 年 11 月 6 日
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

採用された回答

Bruno Luong
Bruno Luong 2018 年 11 月 6 日
c = [a(randperm(length(a))) b(randperm(length(b)))]
  3 件のコメント
Hajem Daham
Hajem Daham 2018 年 11 月 6 日
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
Bruno Luong
Bruno Luong 2018 年 11 月 6 日
Don't see the pattern.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by