analyze Consecutive points in an array

2 ビュー (過去 30 日間)
ALDO
ALDO 2019 年 5 月 28 日
編集済み: ALDO 2019 年 5 月 31 日
I have an array with following values. I would like to look at 5 consecutive points and see if they meet the following critria and return an logical array. if the criteria is met we get 1 and if not 0.
Data values example:
x=0.045135 -0.03538 0.010979 -0.01464 0.050014 0.563576 1.471152 1.451634 (the actual array is has 20000 elemets).
Criteria:
The point I am looking at is Pi, I would like it to meet thsese citeria Pi>=0.2 P(i+1)>=0.2 P(i+2)>=0.2 P(i-1)<0.2 P(i-2)<0.2
Thank you for your help!
for i=1:lenght(x)
if x(i)>=0.2 && x(i+1)>=0.2 && x(i+2)>=0.2 && x(i-1)<0.2 && x(i-2)<0.2
w(i)=1
else
w(i)=0
end
end

採用された回答

Jos (10584)
Jos (10584) 2019 年 5 月 28 日
編集済み: Jos (10584) 2019 年 5 月 29 日
Let x be your vector.
MyFun = @(i) x(i)>=0.2 && x(i+1)>=0.2 && x(i+2)>=0.2 && x(i-1)<0.2 && x(i-2)<0.2
% MyFun(k) will return true or false by looking at the 5 points surrounding point k
RESULT = false(size(x))
ix = 3:numel(x)-2 % skip first and last elements (default to false)
RESULT(ix) = MyFun(ix)
  1 件のコメント
ALDO
ALDO 2019 年 5 月 31 日
編集済み: ALDO 2019 年 5 月 31 日
Thank you for your answer! It worked perfectly!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by