Effacer les filtres
Effacer les filtres

Matrix reduction to see how many various elements the matrix has

2 vues (au cours des 30 derniers jours)
Homayoon
Homayoon le 1 Fév 2016
Modifié(e) : Stephen23 le 1 Fév 2016
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.

Réponse acceptée

Stephen23
Stephen23 le 1 Fév 2016
Modifié(e) : Stephen23 le 1 Fév 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

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by