Return index of datetime column in a table

조회 수: 2 (최근 30일)
Sonima
Sonima 2019년 8월 26일
편집: Sonima 2019년 8월 27일
Hi!
I have a very long table which I want to return index to specific raws.
>> head(HData)
Time
_____________________
'2019.08.22 12:00:00'
'2019.08.22 12:15:00'
'2019.08.22 12:30:00'
I want to return in dex for the raws
'2019.08.22 12:00:00'
Thanks.
  댓글 수: 1
Ted Shultz
Ted Shultz 2019년 8월 26일
is the time variable a matlab datetime number, or is it a string? This will use much less data, and be easier to work with if it was a datetime.
it usualy isn't too much work to convert strings to datetime arrays.

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

채택된 답변

Akira Agata
Akira Agata 2019년 8월 27일
If your HData.Time column is string:
% index of zero seconds
idx_s = cellfun(@(x) ~isempty(x),regexp(HData.Time,'00$','match'));
% index of zero minutes
idx_m = cellfun(@(x) ~isempty(x),regexp(HData.Time,':00:','match'));
Or, if your HData.Time column is datetime, it becomes much simpler, like:
% index of zero seconds
idx_s = HData.Time.Second == 0;
% index of zero minutes
idx_m = HData.Time.Minute == 0;

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by