MATLAB: Removing non unique elements from an array after n entries

arraysremoving elements

If I have an array:
[1 2 3 4 5 6 8 1 2 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 .... 5]
^
How can I remove the remaining 5s after say, here?

Best Answer

out = yourVector(1:18);