0

I have a vector with timestamps as following:

1521753105.031429052352905
1521753105.081429004669189
1521753105.131428956985474
1521753105.181428909301758
1521753105.231429100036621
1521753105.281429052352905
1521753105.331429004669189
1521753105.381428956985474
1521753105.431428909301758
1521753105.481429100036621
1521753105.531429052352905
1521753105.581429004669189

The current time is:

1521753105.231428861618042

which is in between the 4th and 5th values.

The Values lies between two values

How to determine the lower and upper index to the current time?

Sardar Usama
  • 19,536
  • 9
  • 36
  • 58

2 Answers2

3

Similar to Ander's solution:

find first greater timestamp than your current timestamp. Find last smaller timestamp by subtracting one.

bracket = find(A>v,1) + [-1, 0];
Sardar Usama
  • 19,536
  • 9
  • 36
  • 58
2

One liner trick!

A=%[your numbers]
v=%the value to find its position

braket=find(sort([A,v])==v)+[-1 0]

Assumes that A was sorted originally, of course

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120