if i have two of matrix how to sort them?

조회 수: 3 (최근 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 CenterFile Exchange에서 Testing Frameworks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by