Fill date gap and fill missing data wit NaN

7 Ansichten (letzte 30 Tage)
Davide Cerra
Davide Cerra am 20 Aug. 2020
Kommentiert: Jalaj Gambhir am 24 Aug. 2020
Hello, i have to fill the gaps of these type of data:
Date Temperature
30/4/19 20:10 15.75
30/4/19 20:15 15.65
30/4/19 20:20 15.45
30/4/19 20:25 15.2
30/4/19 20:30 14.95
30/4/19 20:35 14.7
30/4/19 20:40 14.45
30/4/19 20:45 14.2
11/5/2019 13:45 12.8
11/5/2019 13:50 12.9
11/5/2019 13:55 12.8
11/5/2019 14:00 12.8
11/5/2019 14:05 12.8
11/5/2019 14:10 13
i would like to transform them like this:
Date Temperature
30/4/19 20:10 15.75
30/4/19 20:15 15.65
30/4/19 20:20 15.45
30/4/19 20:25 15.2
30/4/19 20:30 14.95
30/4/19 20:35 14.7
30/4/19 20:40 14.45
30/4/19 20:45 14.2
30/4/19 20:50 NaN
30/4/19 20:55 NaN
...................
11/5/2019 13:50 12.9
11/5/2019 13:55 12.8
11/5/2019 14:00 12.8
11/5/2019 14:05 12.8
11/5/2019 14:10 13
thanks!
  1 Kommentar
KSSV
KSSV am 20 Aug. 2020
Create datetime arrays and use setdiff to get indices which are missing and fill thos with NaNs.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jalaj Gambhir
Jalaj Gambhir am 24 Aug. 2020
Hi,
As already pointed out,
startTime = datetime(2019,4,30,20,10,0);
endTime = datetime(2019,4,30,23,55,0);
allRange = startTime:minutes(5):endTime;
dateRangeKnown = [] % initialize the datetime objects for which temperature is known.
[~,indices] = setdiff(allRange, dateRangeKnown);
% Initialize Table appropriately.
Table(indices,2) = {NaN}; % Table contains 2nd column as temperatures.
Hope this helps!
  4 Kommentare
Jalaj Gambhir
Jalaj Gambhir am 24 Aug. 2020
I suspect the issue is because of Input Format mismatch.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Find more on Dates and Time in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by