How can I shuffle a matrix?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Whale Chicken
le 4 Mai 2021
Commenté : Whale Chicken
le 4 Mai 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.
0 commentaires
Réponse acceptée
Scott MacKenzie
le 4 Mai 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!