フィルターのクリア

Efficient way to find the first value that exceeds limits in a 1column array

8 ビュー (過去 30 日間)
Giulia
Giulia 2014 年 9 月 21 日
コメント済み: Star Strider 2014 年 9 月 22 日
Hello,
I have a matrix with only one column of measures (eye coordinates on the screen on the x-axis). The code needs to find the first value that goes beyond a specific limit.
In other words, the matrix starts with values in the range 120:140 (which indicate the position of the eye is approximately on the center of the screen)Then, the values can be either (< 120) or (> 140) (indicating the eye moved towards the left or the right). I need to find the (i-row,1) position in which the values go beyond the limit of 120 or 140 (I cannot know in advance the direction of the eye).
________
i.e the raw data in my matrix could be something like that:
EyeRawData(:,1)= [130,135,125,136,131,...,128,121,116,90,76,65,65,54,65,70]
or
EyeRawData(:,1)= [130,135,125,136,131,...,139,142,156,170,190,191,189,187,190]
I need to count trough the entire rawdata 'how many rows it takes to get to the value 121 (or 142)'. And return EyeRawData (i,1)
___________
So, at the moment, I have written something like this:
l= length(EyeRawData);
for i=1:l
if (EyeRawData(i,l) > 140) || (EyeRawData(i,l) < 120)
position= i;
break
end
end
Can you please tell me whether this is a correct way of doing it or there are more efficient ways?
thank you very much
Giulia

採用された回答

Star Strider
Star Strider 2014 年 9 月 21 日
My approach would be to use the find function:
ERDI = find( (EyeRawData > 140) | (EyeRawData < 120) );
returning the indices of ‘EyeRawData’ that correspond to either condition.
  4 件のコメント
Giulia
Giulia 2014 年 9 月 22 日
Thank you very much Star Strider and Matt J. This is very useful and I can get loads of other important info with just one line.
Best
Giulia
Star Strider
Star Strider 2014 年 9 月 22 日
My pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by