Remove rows with less than certain amount of measurements from timetable
7 ビュー (過去 30 日間)
古いコメントを表示
Hi all,
I have a 517x2 timetable that I've reduced based on some conditions shown in my code below. Next, I want to remove any rows with measurements that do not contribute a full day's worth of measurements. A full day contains 8 measurements, so in the photo we see that rows with April 19 and May 6 dates would be removed, but May 7 and 8 would not since they contain 8 measurements per day each. Please let me know if this does not make sense. Any tips are appreciated, this is my first time using timetables / tables. Thank you very much in advance.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/288560/image.png)
%% Hm0 <4m & Tp > 8s
Hm0_OM = Hm0_yy';
Tp_OM = Tp_yy';
dnum_OM = dnum_yy';
% Create table with values
OM_occ = timetable(dnum_OM, Hm0_OM, Tp_OM);
%Remove values based on O&M requirements
OM_occ(OM_occ.Hm0_OM > 1.5,:)=[];
OM_occ(OM_occ.Tp_OM > 8,:)=[];
% Remove rows that do not contribute to a full day's worth of measurements (8 per day)
2 件のコメント
採用された回答
Hank
2020 年 4 月 29 日
編集済み: Hank
2020 年 4 月 29 日
I have some idea about getting the times and unique times
T = tab.Time
uT = unique(T);
and then checking how many times each unique time appears in T in a for loop. Let me know if it needs tweaking.
rm = zeros(size(T),'logical'); % array tracking rows to be removed
for i=1:length(uT)
A = uT(i)==T; % logical array, size of T
if sum(A)<8 % sum(A) counts the entries with that unique datetime
rm = rm | A; % add the rows to the rm array by logical or.
end
end
T(rm,:) = []; % delete rows that didn't match spec
If we start removing rows within the loop, the loop index will lose sync with the array, hence the rm array.
5 件のコメント
Hank
2020 年 5 月 4 日
The trick was finding a way to compare the datetime objects that would be true if they're the same date (ignoring the time of day). I think converting to strings was a sloppy way to do this, but it allows us to use the unique function and to count dates that are the same with strcmp.
I'd love to see if someone comes up with a cleaner method.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!