Borrar filtros
Borrar filtros

How to retrieve unique columns in a matrix ?

52 visualizaciones (últimos 30 días)
Sai Teja Suggala
Sai Teja Suggala el 10 de Mzo. de 2022
Comentada: Stephen23 el 25 de En. de 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.

Respuesta aceptada

Stephen23
Stephen23 el 10 de Mzo. de 2022
Editada: Stephen23 el 10 de Mzo. de 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 comentarios
Laxmikant Sharma
Laxmikant Sharma el 24 de En. de 2023
Editada: Laxmikant Sharma el 24 de En. de 2023
What if you want the indeces too?
[B idx] = unique(A.', 'rows', 'stable').'
Not working!!!
Stephen23
Stephen23 el 25 de En. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Numeric Types en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by