How can I shuffle a matrix?

조회 수: 3 (최근 30일)
Whale Chicken
Whale Chicken 2021년 5월 4일
댓글: Whale Chicken 2021년 5월 4일
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.

채택된 답변

Scott MacKenzie
Scott MacKenzie 2021년 5월 4일
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
Whale Chicken
Whale Chicken 2021년 5월 4일
THIS WORKED, THANK YOU SOOO MUCH!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by