How to Shuffle some arrays of a matrix? (permutataion matrix considered)
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
alexaa1989
el 12 de Ag. de 2014
Comentada: omar A.alghafoor
el 10 de Oct. de 2020
for shuffling I have this codes so far
nVar=length(x);
cc=randsample(nVar,2);
c1=min(cc)
c2=max(cc)
now I need to shuffle arrays between C1 and C2 without having a number twice. each number has to appear only once
2 comentarios
Adam
el 12 de Ag. de 2014
What do you expect to happen to the data outside of the C1 to C2 range? Are the arrays in question ordered so that data between C1 and C2 will always be contiguous and everything else in the array stays where it is?
The 'unique' function will get rid of duplicates for you.
Respuesta aceptada
Andrei Bobrov
el 12 de Ag. de 2014
n = numel(x);
c = sort(randsample(nVar,2));
r = c(1)+1:c(2)-1;
z = x(r);
x(r) = z(randperm(diff(c)-1));
2 comentarios
Más respuestas (0)
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!