mixing randomly existing values in a vector

10 ビュー (過去 30 日間)
Eliraz Nahum
Eliraz Nahum 2018 年 10 月 5 日
回答済み: Eliraz Nahum 2018 年 10 月 5 日
hello I have a vector of 10 components - [1 1 1 1 1 1 0 0 0 0] I want to randomly (a uniform distribution is preferred) mixing the components of the vector, while making sure that in the end I will have the same amount of 1 and 0 as in the beginning.
a desired result for example: [1 0 1 0 1 0 1 0 1 1]

採用された回答

Bruno Luong
Bruno Luong 2018 年 10 月 5 日
>> a=[1 1 1 1 1 1 0 0 0 0];
>> r = a(randperm(length(a)))
r =
1 1 0 1 0 1 0 1 0 1
>>

その他の回答 (1 件)

Eliraz Nahum
Eliraz Nahum 2018 年 10 月 5 日
thanks a lot

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by