Efficient way to find the first value that exceeds limits in a 1column array
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
Star Strider
il 21 Set 2014
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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!