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!
0 个评论
回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!