Searching for specific pattern and returning 16 values/data characters from the last index of occurrence of my specific pattern
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Welcome guys !
I'm in a process of 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 1 0 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 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 the 16 offset data immediately following my substring from the last index of occurrence of my substring in my 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 return 16 offset data from the last index of occurrence immediately following it.
according to my example the function gets as inputs: (input1, substring) and return a matrix(two dimensional array) that has those outputs:
Output=[0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 ; 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1];
so first row is represent first occurence of 0101 and the 16 offset data that are immediately following it is: 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1
so second row is represent first occurence of 0101 and the 16 offset data that are immediately following it is: 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
number of rows is according to number of occurance of my substring ..so if my substring occured and appeared n times in my input1 , this means my matrix has n rows of the 16 offset data that are immediately following each occurances respectively to each occurance of my substring.
there can't be overlab between first occurance of my substring to next occurance of my substring in my input1, this means there's always at least 16 offset data immediately following each occurance of my substring in my input1.
Could you guys assist and help me to implement that in matlab? thanks alot!
thanks alot for helpers !
0 comentarios
Respuestas (1)
Walter Roberson
el 6 de Ag. de 2020
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 1 0 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ];
substring=[0 1 0 1];
N = 16;
positions = strfind(input1(1:end-N+1), substring);
Output = cell2mat(arrayfun(@(idx) input1(idx+length(substring):idx+length(substring)+N-1), positions, 'uniform', 0 ).');
2 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!