Borrar filtros
Borrar filtros

How can I shuffle a matrix?

5 visualizaciones (últimos 30 días)
Whale Chicken
Whale Chicken el 4 de Mayo de 2021
Comentada: Whale Chicken el 4 de Mayo de 2021
I have a matrix M of 10000 x 4, I want to shuffle the numbers. After that ill be calculating the median But I keet getting an error
M = 10000 x 4 matrix
ExampleFunction(M, 2)
function [] = ExampleFunction(d3, k3)
for i = 1:d3
[~, n3] = size(d3);
idx3 = randperm(n3);
randM3 = d3;
randM3 = (1, idx3) = d3(1, :);
end % for i
disp(randM3)
% Median
for j = 0:length(randM3)
mid3 = randM3(ceil(end/2), :);
end% for j
disp(mid3)
end % Function
Error:
Unrecognized function or variable 'randM3'.
Error in:
for j = 0:(randM3)
I have 2 other matrixes in different functions running in the same method as above with no error, I don't know why I have an error in this one.

Respuesta aceptada

Scott MacKenzie
Scott MacKenzie el 4 de Mayo de 2021
Looking only at your question (How can I shuffle a matrix?), here's one option:
M = [1:5; 6:10; 11:15]
r = randperm(numel(M));
M = M(reshape(r, size(M,1), []))
Output:
M =
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
M =
9 11 13 6 14
10 5 4 3 8
7 2 12 15 1
  1 comentario
Whale Chicken
Whale Chicken el 4 de Mayo de 2021
THIS WORKED, THANK YOU SOOO MUCH!!!

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by