how can i sort columns of a matrix in ascending order using loops without using the functions max,min,sort?

1 回表示 (過去 30 日間)
I have a 15x10 matrix with numbers and i need to sort each column in ascending order

採用された回答

Jonathon Gibson
Jonathon Gibson 2018 年 7 月 1 日
Here's a really simple, inefficient way:
M = rand(15,10)
for col = 1:size(M,2)
for iters = 1:size(M,1)
for row = 1:(size(M,1)-1)
if (M(row,col) > M(row+1,col))
temp = M(row,col);
M(row,col) = M(row+1,col);
M(row+1,col) = temp;
end
end
end
end
M

その他の回答 (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