フィルターのクリア

if i have two of matrix how to sort them?

1 回表示 (過去 30 日間)
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016 年 5 月 9 日
回答済み: Walter Roberson 2016 年 5 月 9 日
if i have this code
x_matrix= [];
value = [];
for k=1:15
x_matrix{k} = randi([0 1],5,5);
value = sum(sum(x_matrix{k}));
end
how can i sort the vector Value from the min value to max value in which the index x_matrix for this value
will be change in the same position to the index value for it ??
  1 件のコメント
Walter Roberson
Walter Roberson 2016 年 5 月 9 日
You should be assigning to value(k) not to value alone.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2016 年 5 月 9 日
ntries = 15;
x_matrix = cell(ntries, 1);
for k = 1 : ntries
x_matrix{k} = randi([0,1], 5, 5);
end
values = cellfun(@nnz, x_matrix);
[sortvalues, sortidx] = sort(values);
smallest_xmatrix = x_matrix{sortidx(1)};
largest_xmatrix = x_matrix{sortidx(end)};

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by