find arrays that are consecutively equal

1 view (last 30 days)
Sehoon Chang
Sehoon Chang on 12 Apr 2020
Edited: Rik on 12 Apr 2020
suppose i have a vector W(idx) = [ ........ 1 4 3 6 7 4 2 6 0 0 0 0 20 6 15 2 3 0 0 0 0 31...... ]
I want to find arrays that have:
  1. z-score value higher than 3,
  2. have a value over 15.
  3. its previous arrays should have at least three times consecutively same value of 0
With the provided exmple vector W(idx), the idx-points that meet above mentioned specifications would be points that has 20 and 31 as W-value.
I have written the first 1 & 2 specifications, but can't figure how to implement the #3.
stdDev = std(W(idx))
meanValue = mean(W(idx))
zFactor = 3 % arbitrary value to filter only outlier with huge value (usually, z factor of 3 -> outlier)
outliers_1 = find((abs(W(idx)-meanValue) > (zFactor * stdDev)) & (W(idx) > 20) )
#3 --> the final outlier's previous arrays should have at least three consecutive value of 0
Maybe in a similar way like this?
outlier = find(W(outliers_1 - 1) == W(outliers_1 -2) == W(Outliers_1 - 3) == 0)
Please help me out how to find arrays that have consecutively 0 before previously stated outlier_1 position
Thanks

Accepted Answer

Rik
Rik on 12 Apr 2020
Edited: Rik on 12 Apr 2020
I adapted your input data a bit. The code below should be easy to modify for your goals.
W= [ 1 4 3 6 7 4 2 6 0 0 0 0 25 6 15 2 3 0 0 0 0 25];
zFactor = 1;
high_value=15;
run_length=3;
stdDev = std(W);
meanValue = mean(W);
cond1=abs(W-meanValue) > (zFactor * stdDev);
cond2=W >= high_value;
cond3=true(size(W));cond3(1:run_length)=false;
W_shift=W;
for n=1:run_length
W_shift=circshift(W_shift,1);
cond3 = cond3 & W_shift==0;
end
outliers_1 = find( cond1 & cond2 & cond3 );
You can also avoid the loop for the 3rd condition with a convolution:
kernel=[zeros(1,run_length+1) ones(1,run_length)];
cond3b= conv(W==0,kernel,'same')==run_length ;

More Answers (0)

Community Treasure Hunt

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

Start Hunting!