グループごとにretimeを適用する
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
涼輔 前田
el 28 de Nov. de 2021
日付とグループ番号が記載された2列のtimetableがあります。日付は2019/4~2020/3のもので、グループごとに欠損している日付が異なります。グループごとに欠損した日付をretimeで埋める方法はないでしょうか。
3 comentarios
Hiro Yoshino
el 30 de Nov. de 2021
例えば
newTimetable = retime(oldTimetable,"regular","linear",...
"TimeStep",milliseconds(2));
とすると、2 ms で 再サンプリングできます。
ここを触って、日や時間で埋めることができます。ご参考まで。
Respuesta aceptada
Kojiro Saito
el 30 de Nov. de 2021
Editada: Kojiro Saito
el 30 de Nov. de 2021
【編集後】
いただいたコメントでやりたいことが理解できました。
グループ番号毎にtimeが2019/4/1~2020/3/31で、datacountが0の配列(下記のコードでnewTで定義したもの)を作り、変数Tに含まれている日付とグループ番号の場合はTのdatacountを代入する方法です。
下記のコードで実現できると思います。
[g, groupId] = findgroups(T.group);
timeRange = datetime(2019,4,1):days(1):datetime(2020,3,31); % 2019/4/1~2020/3/31の1日毎の要素
% グループ番号毎にtimeが2019/4/1~2020/3/31で、datacountが0のテーブル
newT = table;
newT.time = repmat(timeRange, [1, length(groupId)])';
newT.datacount(:) = 0;
newT.group(:) = sortrows(repmat(groupId', [1, length(timeRange)])');
% 変数Tに含まれている日付とグループ番号の場合は、Tのdatacountを代入
for n=1:height(T)
idx = (T.time(n) == newT.time) & (T.group(n) == newT.group);
newT.datacount(idx) = T.datacount(n);
end
実行してnewTに所望のデータが格納されると思います。
【編集前】
変数Tにtimeとgroupがソートされた状態で格納されているようですので、グループ毎に処理させずにテーブルの全行について、time列で日付が欠損してNaTになっている部分をfillmissingで埋める方法でどうでしょうか。
T.time = fillmissing(T.time, 'nearest');
5 comentarios
Más respuestas (0)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!