Hi. I'm struggling with how to make my code.
Here is the thing. I want to get a new matrix A such that all duplicated vectors are removed. Here is my matrix A and a new matrix A that I want to get:
A = [1 3; 1 4; 1 3; 1 4; 2 3; 3 4; 3 4; 3 5; 4 5]
new A = [1 3; 1 4; 2 3; 3 4; 3 5; 4 5].
How to write the code to get new A...? I'm trying to make it as a function, however, I don't have clear ideas...
I need some help! Thank you so much!!

 Respuesta aceptada

Voss
Voss el 13 de Jun. de 2022
Editada: Voss el 13 de Jun. de 2022
A = [1 3; 1 4; 1 3; 1 4; 2 3; 3 4; 3 4; 3 5; 4 5];
new_A = unique(A,'rows')
new_A = 6×2
1 3 1 4 2 3 3 4 3 5 4 5

2 comentarios

Sounghwan Hwang
Sounghwan Hwang el 13 de Jun. de 2022
Awesome.... thank you so much. I didn't know that there is a unique function in the Matlab. Really appreciated!!
Voss
Voss el 13 de Jun. de 2022
You're welcome!

Iniciar sesión para comentar.

Más respuestas (1)

nandishwar
nandishwar el 28 de Jul. de 2026 a las 8:23

0 votos

function new_A = remove_duplicate_rows(A)
% REMOVE_DUPLICATE_ROWS Removes duplicate row vectors from matrix A.
% 'rows' treats each row as a single vector.
% 'stable' keeps the original order of the remaining unique rows.
new_A = unique(A, 'rows', 'stable');
end

Categorías

Etiquetas

Preguntada:

el 13 de Jun. de 2022

Respondida:

el 28 de Jul. de 2026 a las 8:23

Community Treasure Hunt

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

Start Hunting!

Translated by