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 件のコメント

sloppydisk
sloppydisk 2018 年 5 月 3 日
https://en.wikipedia.org/wiki/Sorting_algorithm#Popular_sorting_algorithms This might help, if you have a specific question on your attempt we can help you with the syntax.
John BG
John BG 2018 年 5 月 4 日
Hi Ashraf
would it be possible for you to be a bit more specific?
What kind of sorting are you after?
ascending rows descending rows by columns?
sort the rows by their mean? or the variance? or else?
There are many different ways to sort the contents of a matrix.
As soon as you specify a particular sorting algorithm rest assured that the interested readers will be able to supply answers, but until then, all we can do it to guess what algorithm do you really want to go for.
Regards
John BG
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 日

0 投票

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.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

質問済み:

2018 年 5 月 3 日

編集済み:

2018 年 5 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by