MATLAB - 从时间序列对象中获取特定索引

MATLAB - get specific index from Time Series Object

我正在寻找一种简单快速的方法来获取时间序列对象条目的索引。例如:

%ts is a time series object with the following properties:
% Common Properties:
        Name: 'unnamed'
        Time: [70001x1 double]
    TimeInfo: [1x1 tsdata.timemetadata]
        Data: [70001x1 double]
    DataInfo: [1x1 tsdata.datametadata]

%first entry of ts is: 0 (time), 0.0667 (data)    
%second entry of ts is: 0.01 (time), 0.0667 (data)
%adn so on...

%I'm looking for an index i, such that i is the entry at the time 500.00
indexEntry = ts.time(i);
result = indexEntry == 500.00
%and resut should be true
tmp = 1:numel(ts.Time);
index = tmp(ts.time==500); %// 7000-by-1 logical array

Time==500 的时间可以使用 logical indexing 找到。

之后,对于单个索引,以下应该更快:

index = find(ts.time==500);

需要注意浮点数据类型

index = find(abs(ts.time-500)<0.00001);