Borrar filtros
Borrar filtros

Matrix reduction to see how many various elements the matrix has

2 visualizaciones (últimos 30 días)
Dear All,
I have a 1*12 row whose elements are integers. Some of the elements might be repeated. I need to reduce the matrix to a smaller one which just contains the non-zero numbers disregarding of how many time they have been repeated.
for an Example
A = [4, 0, 0, 1, 4, 4, 2, 0, 1, 3, 9, 0]
The desired output is something like
Reduced = [ 4, 1, 2, 3, 9]
Please note that 0 should be excluded. Thank you so much for the help.

Respuesta aceptada

Stephen23
Stephen23 el 1 de Feb. de 2016
Editada: Stephen23 el 1 de Feb. de 2016
You could use unique with the 'stable' option:
>> A = [4, 0, 0, 1, 4, 4, 2, 0, 1, 3, 9, 0];
>> unique(A(A~=0),'stable')
ans =
4 1 2 3 9

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices 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!

Translated by