Filter a table based on date (Error using tabular/do​tParenRefe​rence (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

采纳的回答

J. Alex Lee
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 个评论
BN
BN 2020-2-8
Dear J. Alex Lee,
Thank you so much for your reply. I'm sorry, just a little question: did you know if I want to handle a time range (for instance 1/1/1989 to 1/1/2008) rather than a particular time (like 1/1/2015) what should I do? I guess it's can be something like this:
datelimstr = {'1/1/1989': '1/1/2008'};
datelim = datenum(datelimstr, 'mm/dd/yyyy');
istarget = testtable.date == datelim;
% alternatively
% testtable{:,'date'}
newtable = testtable(istarget,:);
?
Thank you again.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Manage Products 的更多信息

标签

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by