Insert new rows of NaN for missing timestamps in time series.
Show older comments
Hello, I have a time series that is missing some data. In the places where there is a data gap I would like to insert rows of NaN values at the same incremetal time step. The data is organized by a datenum.
Here is the current script I'm using to get the timeseries.
Thanks!
% Read the data.
[num, txt, raw] = xlsread('SFL_2018.xlsx'); % Creates three variables. A number (double), raw (cell), and txt (cell).
% Note that the 'txt' and 'raw' variables contain the decriptions of the columns.
% Rename the numerical matrix and remove the upper 4 rows that originally contained the data headers.
SFL2018 = num(5:end, :);
% Change the first column (excel datenum value) to MATLAB datenum value.
datevec = datetime(SFL2018(:,1),'ConvertFrom','excel');
date_num = datenum(datevec);
SFL2018 = [date_num SFL2018(:, 2:end)];
% Rename the 'txt' cell to 'header' and clear unused variables.
header = txt(1:4,:);
clearvars('num', 'txt', 'raw', 'date_num');
Accepted Answer
More Answers (1)
Peter Perkins
on 31 Jan 2019
1 vote
I recommend you use a timetable. Read your data in using readtable, then use table2timetable. The retime function makes what you want one line.
1 Comment
Eric Escoto
on 1 Feb 2019
Categories
Find more on Time Series Events in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!