필터 지우기
필터 지우기

Sorting 2D matrix

조회 수: 11 (최근 30일)
Ashraf Hisham
Ashraf Hisham 2018년 5월 3일
편집: Ameer Hamza 2018년 5월 4일
i wanna sort a 2D Matrix like
a = [1 3 0;5 2 8;4 7 10]
without using any existing function in MATLAB like sort,.... i need an algorithm to sort element by element can any one help ? to be
a = [0 1 2;3 4 5;7 8 10]
  댓글 수: 4
per isakson
per isakson 2018년 5월 4일
Homework?
See also: Bubble sort
Jan
Jan 2018년 5월 4일
Sorting a matrix elementwise is a strange job. If you do not consider the rows or columns, why is the input and output a matrix and not a vector? Please confirm that this does exactly what you want with Matlab commands:
a = [1 3 0;5 2 8;4 7 10]
b = reshape(sort(a(:)), size(a))
"No existing Matlab functions" cannot work. Even "=" calls subasgn and ">" calls the gt function. Without built-in functions, there is almost nothing, what can be done in Matlab at all.

댓글을 달려면 로그인하십시오.

답변 (1개)

Yuvaraj Venkataswamy
Yuvaraj Venkataswamy 2018년 5월 4일
Use this commands where a is input matrix and S_a is the your required answer.
a = [1 3 0;5 2 8;4 7 10]
b=sort(a(:));
S_a=vec2mat(b,3);
  댓글 수: 1
Ameer Hamza
Ameer Hamza 2018년 5월 4일
편집: Ameer Hamza 2018년 5월 4일
The question specifically mentioned not to use built-in sort() function.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by