How can I shuffle a matrix?
조회 수: 3 (최근 30일)
이전 댓글 표시
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
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!