How to find the indices of element occuring once in a vector?
Mostrar comentarios más antiguos
Hello all
I want to know...How can I get the indices of a value that is occuring only once in a vector...please guide.
Example: A=[1 1 0 -1 0 0 1 0 1 1]
Task: To identify the indices of -1 (as it is occuring only once) in A.
Please Help!!!
Regards
Respuesta aceptada
Más respuestas (3)
George Papazafeiropoulos
el 23 de Mayo de 2014
Editada: George Papazafeiropoulos
el 23 de Mayo de 2014
A=[1 1 0 -1 0 0 1 0 1 1];
[~,c]=histc(A,unique(A));
out=A(c==1);
2 comentarios
Sameer
el 23 de Mayo de 2014
Cedric
el 23 de Mayo de 2014
Sagar, you should take the time to understand his example. In particular, see what c is, what c==1 is, etc. Maybe read about logical indexing, and if you cannot use the latter and really need the position of unique element(s), read about FIND.
Mahdi
el 23 de Mayo de 2014
If you're looking specifically for the value of -1, you can use the following:
index1=find(A==-1)
George Papazafeiropoulos
el 23 de Mayo de 2014
Editada: George Papazafeiropoulos
el 23 de Mayo de 2014
A=[1 1 -1 0 0 0 1 0 1 1];
[~,c]=histc(A,unique(A));
out=find(c==1);
3 comentarios
Sameer
el 23 de Mayo de 2014
George Papazafeiropoulos
el 23 de Mayo de 2014
Try the above code for different A. Define A as you want and then execute the two last lines of the code. I think it works...
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
