How to extracy table rows by date?

2 views (last 30 days)
THIAGO DOMINGUES
THIAGO DOMINGUES on 9 May 2019
Answered: Peter Perkins on 14 May 2019
How can one extract table rows by unique dates? If there is a data set where the first column is the date (MM/dd/yyyy), can one create a matrix with unique dates and then extract for each only the rows containing that date?
ExpirationDates = quotedata(:,1); %extract expiration dates
uniqueDates = unique(ExpirationDates); %build expiration dates table
quotedata = table2timetable(quotedata);
for k=1:height(uniqueDates)
thisDate = (uniqueDates(k,:));
indexesWithThisDate = (ExpirationDates == thisDate);
% Extract all rows with this date and put into a cell array.
theseData = array(indexesWithThisDate, 12); % Get col 12
% Assign to a new cell
ca{k} = theseData;
end
I get the following error message:
"Undefined operator '==' for input arguments of type 'table'.
Error in QuotesProcessor (line 13)
indexesWithThisDate = (ExpirationDates == thisDate);"

Answers (1)

Peter Perkins
Peter Perkins on 14 May 2019
Looking at your code, you seem to be creating a timetable with no data, just row times. That doesn't seem useful. But then "array" is, maybe, a table or something with data? This doesn't seem the right way to go about things.
The answer to your specific question is, (ExpirationDates.Time == thisDate). But there have to be better ways to go about whatever it is you are doing.

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!