Delete days containing less than a specified amount of values
8 views (last 30 days)
Show older comments
Hello,
I have large datasheets containing dates and values on those dates, like this:
09/02/2018 670
09/02/2018 1093
10/02/2018 8392
...
..
Of course this is a very small example. I am not interested in the values behind each datapoint but rather the amount of data belonging to each date. So for 09/02/2018 this would be an amount of 2. I have figured out how to 'tally' these points with this code:
Adt = datetime(TimeAD(:,1), 'Format','dd/MM/yyyy');
[H,E] = discretize(Adt, 'day');
Tally = accumarray(H, 1);
assignin('base', 'Result', Result)
assignin('base', 'Tally', Tally)
How can I delete the date and all the values belonging to this date if the tally values are less than a certain amount? So if I chose a value of 4 datapoints on 09/02/2018, then the 2 would not suffice and should be removed from the datasheet.
0 Comments
Accepted Answer
Guillaume
on 10 May 2018
Note that your
[H,E] = discretize(Adt, 'day');
Tally = accumarray(H, 1);
could be written more simply as:
Tally = histcounts(Adt, 'BinMethod', 'day');
The way to get what you want is to indeed use histcounts:
[Tally, ~, bin] = histcounts(Adt, 'BinMethod', 'day');
binstoremove = find(Tally <= 2); %2 being the threshold at which you want to remove elements
toremove = ismember(bin, binstoremove);
Adt(toremove) = [];
More Answers (0)
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!