Borrar filtros
Borrar filtros

swapping elements in matlab?

6 visualizaciones (últimos 30 días)
Eric
Eric el 17 de Dic. de 2013
Respondida: Suneesh el 17 de Dic. de 2013
How would I swap elements randomly in matlab? E.G I have a matrix M=Randi(3,10); and I want to swap its elements/cells around randomly.

Respuesta aceptada

Suneesh
Suneesh el 17 de Dic. de 2013
M=randi(3,10);
M can then be linear indexed by the set [1,30] since there are 30 elements. So you could get a RANDom PERMnutation of that by using RANDPERM.
idx = randperm(30)
Then
Mnew = M([idx]);
and shape up Mnew
Mnew = reshape(Mnew,3,10)

Más respuestas (0)

Categorías

Más información sobre Just for fun en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by