Sort random number at a matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Guilherme Lopes de Campos
el 26 de Sept. de 2023
Respondida: Dyuman Joshi
el 26 de Sept. de 2023
Dear community,
I would like to sort a matrix size (4998x2) on random form.
The follow code it was used:
n=4998
Matrixw = repmat(x, 1, ceil(n/numel(x)));
Matrixw = Matrixw(randperm(n));
The head of data is:
TT Test1
TT Test2
TT Test3
TT Test4
CN Test5
CN Test6
CN Test7
CN Test8
CN Test9
CN Test10
SN Test11
SN Test12
SN Test13
SN Test14
SN Test15
SN Test16
SN Test17
Using the code above, just first column is random sort, but, I need that respectivly both column of the matrix are random sort, in the other words:
SN Test17
TT Test4
CN Test7
Each pair of variable is random sort, but together.
Can help me, please?
Yours faithfully
0 comentarios
Respuesta aceptada
Voss
el 26 de Sept. de 2023
% a matrix
M = reshape(1:100,[],2)
% randomly reorder the rows
M = M(randperm(size(M,1)),:)
0 comentarios
Más respuestas (1)
Dyuman Joshi
el 26 de Sept. de 2023
Do you mean like this -
n = 10;
x = [(1:10)' (10:-1:1)']
idx = randperm(n)
x = x(idx,:)
0 comentarios
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices 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!