필터 지우기
필터 지우기

How to filter a table with a date field

조회 수: 2 (최근 30일)
Manny
Manny 2024년 2월 19일
댓글: Dyuman Joshi 2024년 2월 19일
Hi everyone
I have an n by m table called Table1 that needs to be filtered. I am new to Matlab so I am learning as I go. I need to return all the rows in Table1 when TRADE_DATE <= Feb 16 2024. How do I this? Thank you
SYMBOL TRADE_DATE
_______ ___________
{'SPX'} 03-Jun-2014
{'SPX'} 09-Jun-2014
{'SPX'} 10-Jun-2014

채택된 답변

Dyuman Joshi
Dyuman Joshi 2024년 2월 19일
You can directly compare dates and use logical indexing to get the corresponding data -
%date to compare
dt = datetime(2014, 2, 16);
%Data
vec = table(rand(4,1), datetime(2014, 2, [11 13 17 19]).')
vec = 4×2 table
Var1 Var2 ________ ___________ 0.33292 11-Feb-2014 0.52272 13-Feb-2014 0.095657 17-Feb-2014 0.95912 19-Feb-2014
idx = vec{:,2}<=dt
idx = 4×1 logical array
1 1 0 0
out = vec(idx, :)
out = 2×2 table
Var1 Var2 _______ ___________ 0.33292 11-Feb-2014 0.52272 13-Feb-2014
  댓글 수: 2
Manny
Manny 2024년 2월 19일
it works as expected! thank you so much!!
Dyuman Joshi
Dyuman Joshi 2024년 2월 19일
You're welcome!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by