Delete days containing less than a specified amount of values

8 ビュー (過去 30 日間)
Debbie Oomen
Debbie Oomen 2018 年 5 月 10 日
コメント済み: Debbie Oomen 2018 年 5 月 10 日
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.

採用された回答

Guillaume
Guillaume 2018 年 5 月 10 日
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) = [];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by