find all sequences between delimiters in an array
2 次查看(过去 30 天)
显示 更早的评论
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.
2 个评论
Stephen23
2021-5-11
If the numbers are always positive integers <10 then this is easy. If the values can be >=10 or if you want to consider non-integer values then the task requires a bit more thought. What restrictions/limits do you have on the number values?
采纳的回答
更多回答(1 个)
Jonas
2021-5-11
you could convert the array to a string or char array and then use extractBetween() which does what you want
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!