필터 지우기
필터 지우기

How do I determine the closest upcoming index (given a vector of the indices of interest) to each value in a vector of timestamps?

조회 수: 4 (최근 30일)
I have a record of timestamps at 5 minute intervals. I want to calculate the time (ideally in hours) until the next tide change given the indices of the tide changes. I think the first step is to determine the closest upcoming tide change index to each timestamp in the vector (I need to identify the NEXT tide change even if the previous tide change is closer).
I have attached the data here (data.m) where MX (4888x1 double) is my timestamp vector (in matlab time) and flood (32x1 double) identifies the indices of the flood tides starting.
I cannot for the life of me figure out how to translate this problem into Matlab and I'm not sure what to search in the Matlab help section to figure it out either.
Thank you in advance for any help!
  댓글 수: 1
Adam Danz
Adam Danz 2020년 9월 15일
If "MX" are your timestamps and "flood" are the indices of the time stamps that indicate tide-change, then the time of the tide changes are just MX(flood).
Is your goal to compute the time until the next tide change for each of the 4000+ timestamps?

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

답변 (1개)

Walter Roberson
Walter Roberson 2020년 9월 15일
tt = vector_of_tide_times; %must be in increasing order
ts = vector_of_timestamps; %does not need to be in order
nextidx = interp1(tt, 1:length(tt), ts, 'next');
For each entry in ts, the value of nextidx would be the index into tt at which tt(nextidx(K)) is the next tide time after ts(K)
This is not the only possibility. For example, there are approaches involving
bin = discretize(-ts, fliplr(-tt));
nextidx = length(tt) - bin + 1;
The negatives there are because discretize takes the previous edge not the next edge, and you can map the "next edge" problem to that by taking the negatives of both sides so that the next edge is more negative and so is "previous" in the negative space.
  댓글 수: 4
Heidi Hirsh
Heidi Hirsh 2020년 9월 15일
min(flood) = 6
max(flood) = 4770
min(MX) = 7.3690e+05
max(MX) = 7.3692e+05
min(datetime(datevec(MX))) = 23-Jul-2017 12:00:00
max(datetime(datevec(MX))) = 09-Aug-2017 11:15:00

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

카테고리

Help CenterFile Exchange에서 Oceanography and Hydrology에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by