グループごとにretimeを適用する
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
日付とグループ番号が記載された2列のtimetableがあります。日付は2019/4~2020/3のもので、グループごとに欠損している日付が異なります。グループごとに欠損した日付をretimeで埋める方法はないでしょうか。
3 Kommentare
Hiro Yoshino
am 30 Nov. 2021
例えば
newTimetable = retime(oldTimetable,"regular","linear",...
"TimeStep",milliseconds(2));
とすると、2 ms で 再サンプリングできます。
ここを触って、日や時間で埋めることができます。ご参考まで。
Akzeptierte Antwort
Kojiro Saito
am 30 Nov. 2021
Bearbeitet: Kojiro Saito
am 30 Nov. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!