Deleting erroneous data from a table

1 view (last 30 days)
James Cross
James Cross on 30 Nov 2022
Answered: Kartik on 21 Mar 2023
I have multiple months of data consisting of 96 entries per day. I need a code segment that will allow me to quickly check each day ( 1 thru 31) to see if it in fact has the required number of entries (should be 96). I need to identify these items indices and remove them from ixt.
So far I have this mess: (I changed the daily input to 97 in an attempt to force a reaction). There has to be a better way... since this didn't work.
ixt = find(deviceColumn == deviceNumber);
dailyInput = 97;
data_check = DateTime(ixt);
sampleDays = dateshift(data_check,'start','day');
check_results = groupsummary(table(sampleDays),1);
days_v = height(check_results(:,2));
ixt_indrem = zeros(1,days_v);
counts = table(check_results(:,2));
dailyInput_t = table(96*ones(31,1));
ixt_indremove = setdiff(counts,dailyInput_t);
I tried using ixt_indremove = setdiff(counts,dailyInput_t); but I keep getting this "Error using tabular/union
A and B must both be tables, or both be timetables." which confuses me because my variables "counts" and "dailyInput_t" are both tables of the same size.

Answers (1)

Kartik
Kartik on 21 Mar 2023
Hi,
The error message you are receiving suggests that 'counts' and 'dailyInput_t' are not both tables or timetables, as required by the 'setdiff' function. One way to fix this is to convert both 'counts' and 'dailyInput_t' into ordinary arrays using the 'table2array' function before passing them to 'setdiff'.

Categories

Find more on Tables in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!