Hi,
My question is as follows:
Given an array N (see below) and a key value, I would like to identify the start and end indices of the pattern associated with the key.
N = [1 1 2 2 2 2 3 3 3 4 4 4 4 1 1 1 1 2 2 2 3 3 3 3 3];
key = 2;
For example, in the above, the pattern associated with '2' can be captured by a sequence of start indices and end indices. Thus, I would like the output:
start_indices = [3 18]
end_indices = [6 20]
How can I do this in MATLAB? Any help appreciated. Thanks in advance!
PS. The broader pattern in this problem is always cyclical. For example, a sequence of 1's is always followed by sequence of 2's, followed by sequence of 3's, followed by sequence of 4's and then back to a sequence of 1's.