How to retrieve unique columns in a matrix ?
42 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Stephen23
on 10 Mar 2022
Edited: Stephen23
on 10 Mar 2022
A = [1,-1,1,1;1,1,1,1;2,1,1,1];
B = unique(A.','rows','stable').'
2 Comments
Laxmikant Sharma
on 24 Jan 2023
Edited: Laxmikant Sharma
on 24 Jan 2023
What if you want the indeces too?
[B idx] = unique(A.', 'rows', 'stable').'
Not working!!!
Stephen23
on 25 Jan 2023
"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.'
idx
More Answers (0)
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!