필터 지우기
필터 지우기

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

조회 수: 17 (최근 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