How to retrieve unique columns in a matrix ?

36 次查看(过去 30 天)
I would like to retrieve all the unique columns in a matrix..
If my matrix =
1 -1 1 1
1 1 1 1
2 1 1 1
UniqueColumns =
1 -1 1
1 1 1
2 1 1
Thank you before hand.

采纳的回答

Stephen23
Stephen23 2022-3-10
编辑:Stephen23 2022-3-10
A = [1,-1,1,1;1,1,1,1;2,1,1,1];
B = unique(A.','rows','stable').'
B = 3×3
1 -1 1 1 1 1 2 1 1
  2 个评论
Laxmikant Sharma
Laxmikant Sharma 2023-1-24
编辑:Laxmikant Sharma 2023-1-24
What if you want the indeces too?
[B idx] = unique(A.', 'rows', 'stable').'
Not working!!!
Stephen23
Stephen23 2023-1-25
"What if you want the indeces too?"
A = [1,-1,1,1;1,1,1,1;2,1,1,1];
[B,idx] = unique(A.','rows','stable');
B = B.'
B = 3×3
1 -1 1 1 1 1 2 1 1
idx
idx = 3×1
1 2 3

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by