MATLAB Answers

0

mixing randomly existing values in a vector

Asked by Eliraz Nahum on 5 Oct 2018
Latest activity Answered by Eliraz Nahum on 5 Oct 2018
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]

  0 Comments

Sign in to comment.

Tags

Products


Release

R2018a

2 Answers

Answer by Bruno Luong
on 5 Oct 2018
 Accepted Answer

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

  0 Comments

Sign in to comment.


Answer by Eliraz Nahum on 5 Oct 2018

thanks a lot

  0 Comments

Sign in to comment.