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
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!