Returning specific substring after occurance of searched substring

1 vue (au cours des 30 derniers jours)
Mohamed Jamal
Mohamed Jamal le 12 Août 2020
Modifié(e) : Mohamed Jamal le 12 Août 2020
Hi guys !
I'm in a struggle for doing a function in matalb that does this thing:
it gets as input array of integers values that are zero or one, the input is a vector or matrix 1XN or NX1 includes 0 or 1 values. For instance:
input1=[0 0 0 0 0 1 0 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 ]; % it's array of integer values of 0 or 1
I want to search for specific substring which it's given in my case the substring is:
substring=[0 1 0 1] % it's array of integer values of 0 or 1
so I want to search for my giving substring in my input1, and to return at each occurance of my substring in input1 all offset data immediately following my substring from the last index of occurrence of my substring in my input1 till the index ( length(input1)-sizeChangeAble).
the parameter sizeChangeAble is a constant paramter that I could play with it's value when I call to the function, this means the the function gets as inputs :
first input: a string -array/vector of chars- called input1.
second input is substring called : substring
third input is an integer variable/parameter called sizeChangeAble. (the parameter sizeChangeAble is an integer ranges between 0<sizeChangeAble<length(input1))
to clarify more, So if I have input1 as I mentioned above, and constant substring= [0 1 0 1] which it's constant vector/array that Im searching for it in my input1. then what I want to do is to find each occurrence of substring in my input1 and all offset data from the last index of occurrence immediately
following it till the index ( length(input1)-sizeChangeAble).
according to my example the function gets as inputs: (input1, substring, sizeChangeAble) and return a matrix(two dimensional array) that has those outputs:
my parameter sizeChangeAble value in my case is 0 (I chosed to be zero..but it could be any number from 0 - infinity ),
so the output:
Output=[ 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1];
so we see here occurence of 0101 in my input1 and all offset data that are immediately following it till the index ( length(input1)-sizeChangeAble) is: 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
the output is a matrix MXN that every row represent all offset data that are following it till the index ( length(input1)-sizeChangeAble) this means my matrix has n rows of the all offset data that are immediately following each occurances till the index ( length(input1)-sizeChangeAble).
for example : first row represents first occurance (all offset data following it according to what explained above) , second row represents second occurance(all offset data according to what explained above) ..etc , so number of rows are representing implicitly number of occurance of my substring in my input1 !
there can't be overlab between first occurance of my substring to next occurance of my substring in my input1, this means I will always return at every occurance of my substring all the offset data that immediately following each occurance of my substring in my input1 till the index ( length(input1)-sizeChangeAble) - it might be that all returned offset data that follows specific occurance include other occurances and that's fine I return them all ..."all the offset data is returned at each occurance till the index ( length(input1)-sizeChangeAble)" .
Could you guys assist and help me to implement that in matlab? thanks alot!
thanks alot for helpers !

Réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by