Check if condition happened in previous values

1 view (last 30 days)
Alex Regner
Alex Regner on 15 Feb 2022
Edited: DGM on 15 Feb 2022
cctbbo = 100.*(Close + 2.*movstd(Close,[BBOlength 0]) - movavg(Close, 'simple', BBOMAlength ))./(4 .*movstd(Close,[BBOlength 0]));
BBobline = 80;
BBosline = 20;
sl1 = cctbbo < BBosline;
Basically I need to check if sl1 is true for any of the previous 20 values at any point in the vector Close. Pretty new to MatLab so I'd appreciate the help. Thanks!

Answers (1)

DGM
DGM on 15 Feb 2022
Edited: DGM on 15 Feb 2022
Consider the simplified example:
cctbbo = randi([10 99],1,40);
BBosline = 20;
sl1 = cctbbo < BBosline; % some logical vector
wsize = 5; % shorter window for demonstration
sl2 = imdilate(sl1,[zeros(1,wsize+1) ones(1,wsize)]); % offset moving maximum filter
[sl1; sl2] % compare input and output
ans = 2×40 logical array
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!