Sorting 2D matrix

6 visualizzazioni (ultimi 30 giorni)
Ashraf Hisham
Ashraf Hisham il 3 Mag 2018
Modificato: Ameer Hamza il 4 Mag 2018
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 Commenti
per isakson
per isakson il 4 Mag 2018
Homework?
See also: Bubble sort
Jan
Jan il 4 Mag 2018
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.

Accedi per commentare.

Risposte (1)

Yuvaraj Venkataswamy
Yuvaraj Venkataswamy il 4 Mag 2018
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 Commento
Ameer Hamza
Ameer Hamza il 4 Mag 2018
Modificato: Ameer Hamza il 4 Mag 2018
The question specifically mentioned not to use built-in sort() function.

Accedi per commentare.

Categorie

Scopri di più su Shifting and Sorting Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by