Which function should I use here to group my matrix?

So let's say I have this matrix in Matlab.
A = [1 0 0;
2 0 0;
1.1 0 0;
2.1 0 0;
1.2 0 0;
2.2 0 0]
The thing is in my case, the values of row 1,3 and 5 are same and values of row 2,4 and 6 are same. And I want to write my new matrix like this.
B = [1 0 0;
1.1 0 0;
1.2 0 0;
2 0 0;
2.1 0 0;
2.2 0 0]
Someone can help me, what function should I use here. I beleive this is something related to group function, but didnt findout able to anything which I can use.
Appreciate your help,
Thank you :).

 採用された回答

madhan ravi
madhan ravi 2018 年 11 月 21 日
編集済み: madhan ravi 2018 年 11 月 21 日

1 投票

A = [1 0 0;
2 0 0;
1.1 0 0;
2.1 0 0;
1.2 0 0;
2.2 0 0]
B = sortrows(A)

4 件のコメント

Ketan Sahu
Ketan Sahu 2018 年 11 月 21 日
編集済み: Ketan Sahu 2018 年 11 月 21 日
Hey Madhav, Thanks for the answer.
Could you help me with this.
if I have this matrix.
A = [1 0 0;
-2 0 0;
1.1 0 0;
-2.1 0 0;
1.2 0 0;
-2.2 0 0]
and the answer I want is this,
B = [1 0 0;
1.1 0 0;
1.2 0 0;
-2 0 0;
-2.1 0 0;
-2.2 0 0].
If i use here the sort function, I will get this
B = sort(A)
B = [-2.2 0 0;
-2.1 0 0;
2 0 0;
1 0 0;
1.1 0 0;
1.2 0 0].
In my first question I was wrong with my interpretations.
madhan ravi
madhan ravi 2018 年 11 月 21 日
Anytime :)
David Hill
David Hill 2018 年 11 月 21 日
Try,
[~,x]=sortrows(abs(A));
B=A(x,:);
Ketan Sahu
Ketan Sahu 2018 年 11 月 23 日
Hello David Hill ,
Thank you for your answer. My code is working good.
Appereicate your efforts. :D

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

質問済み:

2018 年 11 月 21 日

コメント済み:

2018 年 11 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by