Borrar filtros
Borrar filtros

mixing randomly existing values in a vector

5 visualizaciones (últimos 30 días)
Eliraz Nahum
Eliraz Nahum el 5 de Oct. de 2018
Respondida: Eliraz Nahum el 5 de Oct. de 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]

Respuesta aceptada

Bruno Luong
Bruno Luong el 5 de Oct. de 2018
>> 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
>>

Más respuestas (1)

Eliraz Nahum
Eliraz Nahum el 5 de Oct. de 2018
thanks a lot

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by