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일

0 개 추천

>> 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개)

카테고리

도움말 센터File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품

릴리스

R2018a

태그

질문:

2018년 10월 5일

답변:

2018년 10월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by