Check if condition happened in previous values

1 次查看(过去 30 天)
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!

回答(1 个)

DGM
DGM 2022-2-15
编辑:DGM 2022-2-15
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

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by