How to delete duplicate values from an array or a vector
180 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
How to delete duplicate values from an array or a vector
Hi, how do I delete duplicate values from an array or a vector provided that unique function is not used and that the place of the value does not remain empty or zero. The result is like this
a=[1 2 3 6 1 3 1];
a=[1 2 3 6]
b=[1 1 3
3 4 5
4 9 1];
b=[1 3 4 5 9]
5 comentarios
KALYAN ACHARJYA
el 10 de Feb. de 2021
Editada: KALYAN ACHARJYA
el 10 de Feb. de 2021
@Matt J Exactly, so valid Question
:)
Respuesta aceptada
Jan
el 10 de Feb. de 2021
Editada: Jan
el 10 de Feb. de 2021
b=[1 1 3
3 4 5
4 9 1];
% The clean solution:
b = unique(b(:).')
% [1 3 4 5 9]
% Without unique:
bs = sort(b(:).');
result = bs([true, diff(bs) ~= 0])
% [1 3 4 5 9]
% For a stable output (order of elements does not change):
[bs, vec] = sort(b(:).');
uvec(vec) = [true, diff(bs) ~= 0];
result = b(uvec);
% [1 3 4 5 9]
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!