Filter a table based on date (Error using tabular/dotParenReference (line 95) Unrecognized row name '01/00/0000'.)
16 次查看(过去 30 天)
显示 更早的评论
Hey all,
I want to filter a huge table (namely testtable) based on a desired date at the date column. I was read Matlab documentation and used this code:
tr = datestr(1/1/1989,'mm/dd/yyyy');
foundedrows = testtable(testtable.date(tr),:);
But unfortunately, I gave this error:
Error using tabular/dotParenReference (line 95)
Unrecognized row name '01/00/0000'.
then I try to use this code below but it doesn't work too:
idx = testtable(:,6)== 1/1/1989; % 6 is column number of date in testtable I know this is hard coding but I dont know how to fix it
tablenew = testtable(idx,:);
the error is:
Undefined operator '==' for input arguments of type 'table'.
Here is an example of what I'm looking for:
Name value date elevation
------------ ----------- --------- -----------
Dez 0.25 1/1/2015 18.5
Arak 1 2/1/2015 150
Ahaz -0.25 3/1/2015 0
Anad -0.80 1/1/2015 215
If I want 1/1/2015 data I want to select whole rows:
Name value date elevation
------------ ----------- --------- -----------
Dez 0.25 1/1/2015 18.5
Anad -0.80 1/1/2015 215
As the original table has a large size so I cut a part of it and attached it here.
Any advice is highly appreciated
Thank you in advance
0 个评论
采纳的回答
J. Alex Lee
2020-2-8
The second way is almost right, but when you use () on testtable, you are extracting a subtable, rather than the datetime array holding your dates
targetdate = datetime(1989,1,1); % datestr(1/1/1989,'mm/dd/yyyy');
istarget = testtable.date == targetdate;
% alternatively
% testtable{:,'date'}
newtable = testtable(istarget,:);
2 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Manage Products 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!