Adding rows when missing seconds in a time serie

I have a data time serie that looks like this:
2015.03.05 00:00:00 2.3
2015.03.05 00:00:01 2.34
2015.03.05 00:00:02 2.41
2015.03.05 00:00:03 2.53
2015.03.05 00:00:04 2.43
2015.03.05 00:00:05 2.44
2015.03.05 00:00:06 2.36
2015.03.05 00:00:07 2.41
2015.03.05 00:00:12 2.43
2015.03.05 00:00:15 2.41
The time serie is sampled for every second but sometimes there is a jump, for example between 00:00:07 and 00:00:12. Where there is a jump in time I would like to add a row with the missing second and with the value from the second before, for example adding the row 2015.03.05 00:00:08 2.41. Does anyone know how to do this?

댓글 수: 2

Jan
Jan 2017년 2월 8일
Please post the input data in valid Matlab syntax. It is not clear, if this is a table, a cell array, a text file or a cell string.
It is a csv.file that is imported from an excel-file on a Mac computer.

댓글을 달려면 로그인하십시오.

답변 (2개)

Jan
Jan 2017년 2월 8일
편집: Jan 2017년 2월 8일

0 개 추천

Assuming, thet input is a cell array (it takes some time to edit the input, such that it is usable for testing. This time is wasted, if the assumption obout the input format is wrong):
[EDITED, Input format adjusted according to comment, 08.02.2017 14:12 UTC]
Date = {'2015.03.05 00:00:00', ...
'2015.03.05 00:00:01', ...
'2015.03.05 00:00:02', ...
'2015.03.05 00:00:03', ...
'2015.03.05 00:00:04', ...
'2015.03.05 00:00:05', ...
'2015.03.05 00:00:06', ...
'2015.03.05 00:00:07', ...
'2015.03.05 00:00:12', ...
'2015.03.05 00:00:15'};
Value = {2.3; 2.34; 2.41; 2.53; 2.43; 2.44; 2.36; 2.41; 2.43; 2.41};
Time = datenum(Date);
Sec = round((Time - Time(1))* 86400) + 1;
Index = zeros(1, Sec(end));
Index(Sec) = 1;
Index = cumsum(Index);
FullTime = cellstr(datestr(Time(1) + (0:Sec(end)-1) / 86400));
FullValue = Value(Index);

댓글 수: 2

This is what I have, only the date and time are in different cells. I cannot seem to get it to work if they are not in the same cell. Do you know how to fix this?
Jan
Jan 2017년 2월 8일
편집: Jan 2017년 2월 8일
@malinri: Again I've used a minute, to type a guessed format for the input data. Please post the data such that it can be used by copy&paste.
I've modified the code slightly to work with 2 different input cells.

댓글을 달려면 로그인하십시오.

Peter Perkins
Peter Perkins 2017년 2월 8일

0 개 추천

If you have R2016b, timetables and the retime method, called with 'secondly' and 'FillWithMissing', does exactly this.
Even prior to R2016b, I think you'd be better off using datetimes and their intersect method. Create a datetime vector that has all the times, and a numeric vector the same size, filled with NaNs. Call intersect to find the locations in the "complete" vector of the elements of the "partial" vector, and assign the "partial" data values into those locations of the full data vector.

카테고리

도움말 센터File Exchange에서 Data Type Identification에 대해 자세히 알아보기

질문:

2017년 2월 8일

답변:

2017년 2월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by