필터 지우기
필터 지우기

find a string in a Date table column and return its index

조회 수: 2 (최근 30일)
Sonima
Sonima 2018년 8월 12일
편집: Walter Roberson 2018년 8월 12일
Hello! I have a table containing a Date column as the following:
DTM15.Date(1:10,:)
ans =
10×10 char array
'2001-01-02'
'2001-01-02'
'2001-01-02'
'2001-01-02'
'2001-01-03'
'2001-01-03'
'2001-01-03'
'2001-01-03'
'2001-01-03'
'2001-01-03'
I want to find a date in this column for example (2001-01-03) and return its index. I want to also find the first/last index if there are many of 2001-01-03 exist. Thanks.

채택된 답변

Walter Roberson
Walter Roberson 2018년 8월 12일
편집: Walter Roberson 2018년 8월 12일
DTM15.Date = [
'2001-01-02'
'2001-01-02'
'2001-01-02'
'2001-01-02'
'2001-01-03'
'2001-01-03'
'2001-01-03'
'2001-01-03'
'2001-01-03'
'2001-01-03']
[~, idx] = ismember(DTM15.Date, '2001-01-03', 'rows');
first_idx = find(idx, 1, 'first');
last_idx = find(idx, 1, 'last');
Note the order of inputs for ismember()

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by