hello , i want to remove the repeated values in vector without using Unique function
Mostrar comentarios más antiguos
if a = [1 1 2 2 3 3 1] i want the result to be a=[1 2 3] thanks
Respuestas (2)
Birdman
el 1 de Abr. de 2018
A = [1 1 2 2 3 3 1]
[val,idx]=sort(A)
idx=A(idx(1:end-1))==A(idx(2:end))
val(idx)=[] % take it as new A vector
4 comentarios
Ashraf Hisham
el 1 de Abr. de 2018
Birdman
el 1 de Abr. de 2018
Do not need to. My way is more efficient. Try it.
Ashraf Hisham
el 1 de Abr. de 2018
Walter Roberson
el 1 de Abr. de 2018
Okay, suppose you are examining element 4 out of 7, and you need to delete it because it is the same as something earlier. So you x(4)=[] . Now x is length 6. But your for loop still goes to 7.
You need to use one of these techniques:
- keep a record of which items are to be deleted and delete them all at the same time after you have done your loops; or
- start at the end and move to the beginning so that when the array gets shorter that does not matter because you are only going to look at earlier elements. (You might need to adjust this strategy for your situation.)
Walter Roberson
el 1 de Abr. de 2018
find(sparse(a,ones(size(a)),1))
Note: only works for positive integers.
1 comentario
Ashraf Hisham
el 1 de Abr. de 2018
Categorías
Más información sobre Multirate Signal Processing 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!

