I have a column vector with numbers 1 to 8. Under normal circumstances there are 4 consecutive values of each number, moving from 1 to 8 i.e: Perfect_sample=[1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8]';
The pattern starts again from one after the 8.
However, sometimes there are missing values and the vector does not look like the one above but, for example, like this:
Imperefect_sample=[1 1 2 2 2 3 3 3 3 4 5 5 5 5 6 7 7 7 7 8 8]';
My aim is to replace the first two values of each consecutive set of identical numbers with NaN:
Perfect_sample_result=[NaN NaN 1 1 NaN NaN 2 2 NaN NaN 3 3 NaN NaN 4 4 NaN NaN 5 5 NaN NaN 6 6 NaN NaN 7 7 NaN NaN 8 8]'
If there are only two or less consecutive identical numbers, then those numbers should be replaced with NaN.
Imperfect_sample_result=[NaN NaN NaN NaN NaN NaN 2 2 NaN NaN 3 3 NaN NaN NaN NaN NaN NaN 5 5 NaN NaN NaN NaN NaN NaN 7 7 NaN NaN NaN NaN]'
How can I achieve this?