Filter löschen
Filter löschen

How to retrieve unique columns in a matrix ?

52 Ansichten (letzte 30 Tage)
Sai Teja Suggala
Sai Teja Suggala am 10 Mär. 2022
Kommentiert: Stephen23 am 25 Jan. 2023
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.

Akzeptierte Antwort

Stephen23
Stephen23 am 10 Mär. 2022
Bearbeitet: Stephen23 am 10 Mär. 2022
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 Kommentare
Laxmikant Sharma
Laxmikant Sharma am 24 Jan. 2023
Bearbeitet: Laxmikant Sharma am 24 Jan. 2023
What if you want the indeces too?
[B idx] = unique(A.', 'rows', 'stable').'
Not working!!!
Stephen23
Stephen23 am 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.'
B = 3×3
1 -1 1 1 1 1 2 1 1
idx
idx = 3×1
1 2 3

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Numeric Types finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by