Me preguntaba si sería posible utilizar randperm para reorganizar una matriz celular que consiste en columnas idénticas pareadas. Por ejemplo,
S S S S S S L L L L L L
1 1 3 3 5 5 1 1 3 3 5 5
dentro
S S L L S S S S L L L L
3 3 1 1 5 5 1 1 5 5 3 3
Edición: quise decir más como tener columnas emparejadas (o mini-bloques) permutadas al azar para formar una matriz como la de arriba.
S S S S S S L L L L L L
1 1 3 3 5 5 1 1 3 3 5 5
Gracias.
Respuestas
3 para la respuesta № 1c = {"S" "S" "S" "S" "S" "S" "L" "L" "L" "L" "L" "L";
1 1 3 3 5 5 1 1 3 3 5 5}; %// data: cell array
N = 2; %// number of columns per block
d = reshape(c, 2*size(c,1), []); %// pack each group of N columns into a single column
ind = randperm(size(d,2)); %// random permutation of packed-column indices
result = d(:,ind); %// apply those indices
result = reshape(result, size(c,1), []); %// unpack columns
Un resultado de ejemplo es
result =
"L" "L" "L" "L" "S" "S" "S" "S" "L" "L" "S" "S"
[1] [1] [5] [5] [5] [5] [3] [3] [3] [3] [1] [1]