フィルターのクリア

How can I shuffle a matrix?

2 ビュー (過去 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 Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by