Filter löschen
Filter löschen

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

17 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

J. Alex Lee
J. Alex Lee am 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 Kommentare
BN
BN am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Manage Products finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by