Select table data by Date

조회 수: 7 (최근 30일)
Inna Pelloso
Inna Pelloso 2021년 10월 28일
편집: C B 2021년 10월 28일
Hi,
I have a table, where the frist column is the date, and second column is a variable.
''2021-Jan-04'' -0.1581
''2021-Jan-04'' 0.0692
''2021-Jan-04'' 0
''2021-Jan-05'' -0.5150
''2021-Jan-05'' 0.2119
How can I select data in the second columb, by the date in the first colume?
Any help would be appreciated!
Inna

채택된 답변

C B
C B 2021년 10월 28일
편집: C B 2021년 10월 28일
dates = [datetime('today'); datetime('Yesterday') ;datetime('tomorrow')];
data = [-0.1 ; 0 ;0.1];
T = table(dates,data)
T = 3×2 table
dates data ___________ ____ 28-Oct-2021 -0.1 27-Oct-2021 0 29-Oct-2021 0.1
FindDate = '27-Oct-2021';
[val,index] = min(abs((datenum(T.dates)-datenum(FindDate))));
T.data(index)
ans = 0
FindDate = '29-Oct-2021';
[val,index] = min(abs((datenum(T.dates)-datenum(FindDate))));
T.data(index)
ans = 0.1000
FindDate = '28-Oct-2021';
[val,index] = min(abs((datenum(T.dates)-datenum(FindDate))));
T.data(index)
ans = -0.1000

추가 답변 (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