I need some hep finding the index of multiple entries within an array of integers.
e.g:
A = [1 2 3 4 4 5 6 7 8 8 9]
// expected index
indx = [4 5 9 10]
// The entries of A are to be expected to be consecutive...
// e.g something like
// A = [1 2 3 4 4 5 6 7 8 8 9 1 1]
// is not expected
// my current approach:
[nrOfEntries dummy] = size(Data);
uniqueEntries = unique( Data);
[nrOfUniqueEntries dummy]= size(uniqueEntries);
I guess I could now iterate through every unique entry by using something like:
for i = 1: nrOfUniqueEntries
pos = find (Data = uniqueEntry(i) )
end
You select a given index k if A(k)==A(k+1) or A(k-1)==A(k), for relevant values of k, hence if A is of length n you can write this for k=2:n-1 only. For the border cases you have only A(1)==A(2) (first index) and A(n)==A(n-1) (last index). If you want to compute the vector by a single vector operation you can use vector b and its shifted version but in that case you have to add a neutral %f second operand for border cases.