lower and upper index in sorted vector

조회 수: 4 (최근 30일)
Ravindra
Ravindra 2020년 7월 13일
편집: Ravindra 2020년 7월 13일
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
How to determine the lower and upper index to the current time ?
which is in between the 4th and 5th values.
1521753105.231428861618042
  댓글 수: 1
madhan ravi
madhan ravi 2020년 7월 13일
...042 I don’t see that in the above example?

댓글을 달려면 로그인하십시오.

채택된 답변

John D'Errico
John D'Errico 2020년 7월 13일
편집: John D'Errico 2020년 7월 13일
Please don't post pictures of numbers. That makes it more difficult to help you, to answer your question. Why would you make it more difficult for someone to help you?
Regardless, the answer in MATLAB is to use discretize. This will tell you the index of the interval that contains your given time stamp.
T = [ 1521753105.031429052352905
1521753105.081429004669189
1521753105.131428956985474
1521753105.181428909301758
1521753105.231429100036621
1521753105.281429052352905
1521753105.331429004669189
1521753105.381428956985474
1521753105.431428909301758
1521753105.481429100036621
1521753105.531429052352905
1521753105.581429004669189];
T0 = 1521753105.231428861618042;
ind = discretize(T0,T)
ind =
4
I'm not sure if you noticed the problem here, but it should point out something important.
T0 does not actually lies in the interval you show it to lie in. That is, ...231428... comes BEFORE ...231429....
So the timestamp you indicate lies between T(4) and T(5). discretize tells you that. Of course, for this simple problem, sum will tell you as much.
sum(T <= T0)
ans =
4
  댓글 수: 1
Ravindra
Ravindra 2020년 7월 13일
Thanks, I removed the picture and modified the question.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by