Finding the position of specific value in a vector without knowing the exact number
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a vector about the time of an experiment. Now, I want a specific piece of information that was inbetween 3600 and 3800 seconds. However, the measuring points and thus the row numbers, do not match the seconds. So for example, 3600 seconds is the 3482 measuring point/row, but this also changes with my samples.
I thought of finding the correct rows that I want the information of by searching for 3600 and 3800 in the vector. However, there is not a point exactly at 3600 and 3800. I therefore added:
Test = find(abs(Time-3600) <1)
However, this also finds the numbers that are for example 3599. Is there a way in which I can find the number above 3600 closest to 3600. So for example 3600.8, while leaving 3599 out?
2 Commenti
Sargondjani
il 21 Gen 2021
Modificato: Sargondjani
il 21 Gen 2021
If your data is sorted then you could try to find the first entry larger than 3600: tt = find(Time>3600,1). This will find the first entry larger than 3600. (alternatively you could first sort the data).
Otherwise it is a bit more difficult. It is similar to this question (minium + condition):
Risposte (2)
Star Strider
il 21 Gen 2021
The find documentation section Last Several Nonzero Elements will let you return the indices of only some of the elements. You can then choose the ones you want.
0 Commenti
Steven Lord
il 21 Gen 2021
Depending on how you're storing your data and what analysis / manipulation you want to perform on it, storing it in a timetable array and indexing into the rows of the timetable using a timerange may be useful.
n = datetime('now');
t = n + minutes(randi([-5 5], 10, 1));
x = (1:10).'.^2;
tt = timetable(t, x)
r = timerange(n-minutes(2), n+minutes(3), 'closed')
tt(r, :)
0 Commenti
Vedere anche
Categorie
Scopri di più su Preprocessing Data in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!