How to retrieve unique columns in a matrix ?

35 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Stephen23
Stephen23 il 10 Mar 2022
Modificato: Stephen23 il 10 Mar 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 Commenti
Laxmikant Sharma
Laxmikant Sharma il 24 Gen 2023
Modificato: Laxmikant Sharma il 24 Gen 2023
What if you want the indeces too?
[B idx] = unique(A.', 'rows', 'stable').'
Not working!!!
Stephen23
Stephen23 il 25 Gen 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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by