find all sequences between delimiters in an array
Show older comments
Given a sequence of numbers and a start and an end delimiters, how to find the index (start and end) of all possible sequence of numbers between delimiters (sequences can be of any length). Example:
v = [1 1 0 2 0 2 1 2 1 1 1 0 2 1 2 0 0 1 1 1 1 1 1 2 1 0 ]
A list of non-overalpping sequences and their start and end index that begin with 2 and end with 0 would be:
[2 0]
[2 1 2 1 1 1 0]
[2 1 2 0]
[2 1 0]
I feel like this could be solved using regular expression.
Accepted Answer
More Answers (1)
Jonas
on 11 May 2021
0 votes
you could convert the array to a string or char array and then use extractBetween() which does what you want
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!