How to spread out an arry of matrix randomly
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hamid Reza Barzegar
el 18 de Mayo de 2016
Comentada: Hamid Reza Barzegar
el 19 de Mayo de 2016
I have random matrix like this
[2 2 2 2 1 1 1 1 1 -1 -1 -1 -1 -1]
and depend to the result of calculation number of 2 1 -1 will be different but i want to spread these numbers randomly like this e.g. [2 1 2 -1 1 1 2 -1 2 -1 -1 2 ]
how should i do this?
0 comentarios
Respuestas (2)
Walter Roberson
el 18 de Mayo de 2016
YourVector(randperm(length(YourVector)))
2 comentarios
Stephen23
el 19 de Mayo de 2016
@Hamid Reza Barzegar: Walter Roberson's answer clearly uses randperm(length(...)). You have written length(randperm(...).
Roger Stafford
el 18 de Mayo de 2016
Editada: Roger Stafford
el 18 de Mayo de 2016
Let n be the desired length of the result and let a = [2 1 -1] :
p = randi(3,n,1); % <-- Corrected
v = a(p(randperm(n))); % v is your result % <-- Corrected
5 comentarios
Roger Stafford
el 18 de Mayo de 2016
As I state above, your expression is in error in using "length(randperm(Alloc_Sc))" instead of "randperm(length(Alloc_Sc))".
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!