Filter a table based on date (Error using tabular/do​tParenRefe​rence (line 95) Unrecognized row name '01/00/0000'.)

10 views (last 30 days)
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

Accepted Answer

J. Alex Lee
J. Alex Lee on 8 Feb 2020
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 Comments
BN
BN on 8 Feb 2020
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Manage Products in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!