mixing randomly existing values in a vector

9 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by