Identify Multiple, Overlapping, Repetitive Patterns in a Logical Vector

14 次查看(过去 30 天)
I'm trying to identify and separate repetitive patterns referenced to the beginning of a logical vector. I'm still getting my 'chops' on vector math so I ended up created an embarrassingly long brut-force application that sort of worked but is an insult to MatLab. I'm now trying to uses two vectors sliding against each other with logical 'anding'. That's pushing my skills a bit. There are examples here looking for repetitive patterns, but not overlapping. I need some guidance.
The code below generates a test logical vector. Simply stated, I want to extract the same information I used to create the patterns. (The actual patterns will have greater width.) The array (pSet) defines the patterns. Rows represent individual patterns, and columns define the patterns.
(Col 1) The spacing that defines the pattern.
(Col 2) The length of the pattern (cycles) (0 = continue to end)
(Col 3) The offset of the pattern's beginning relative to the start. (Patterns with offsets are 'noise.')
There are certainly pattern structures that will confuse extraction (one pattern is a multiple of another, etc.) I'll deal with that on the backside.
%%
clear
% ------ conditionals (Gen single pattern) --------
only1 = uint16(0); % set to id of individual pattern, leave at 0 otherwise
only2 = only1;
% -------- Pattern Descriptor ---------
pSet = uint16([10 0 0; 6 0 0; 12 16 0; 8 5 0; 5 0 4]);
% -----------------------------
maxL = uint16(200);
v = zeros(maxL,1,'logical');
ofSet = uint16(0);
cycFreq = uint16(0);
cycEnd = uint16(0);
lpSet = uint16(length(pSet));
if only1 == 0
only1 = uint16(1);
only2 = lpSet;
end
for vi = only1:only2
cycFreq = pSet(vi,1); % num data points in spacing
cycBrk = pSet(vi,2); % milepost that ends cycle series
ofSet = pSet(vi,3) + 1; % From beginning
if cycBrk ~= 0
cycEnd = cycFreq*(cycBrk+1);
else
cycEnd = maxL;
end
for vj = ofSet:cycFreq:cycEnd
v(vj) = 1;
end
end

回答(0 个)

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by