To compare every string against the next string, use
sameIdx = find(strcmp(Data(1:end-1),Data(2:end)));
With this, the string at any position of sameIdx
is the same as the string at position sameIdx+1
. Note that this way, you don't need to check for the same previous string.