How to filter a table with a date field
7 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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]).')
idx = vec{:,2}<=dt
out = vec(idx, :)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!