Filling gaps in time series with Nan

2 次查看(过去 30 天)
I have this kind of data.
data = [1 100; 2 200; 3 300; 5 500; 6 600; 7 700; 10 1000;]
The first colum refers to consecutive time series, but there is gaps between 3 and 5 and 7 to 10.
I'd like to make new_data=[1 100; 2 200; 3 300; 4 NaN; 5 500; 6 600; 7 700; 8 NaN; 9 NaN; 10 1000;]
If anyone can help, it would be greatly appreciated.
Thank you!

采纳的回答

Fabio Freschi
Fabio Freschi 2019-9-10
For the particular case
% preliminary setup
newData = [1:10; NaN(1,10)]';
% fill-in
newData(data(:,1),2) = data(:,2)
To make it a little more general
% preliminary setup
newData = [(data(1,1):1:data(end,1))' NaN(data(end,1)-data(1,1)+1,1)]
% fill-in
newData(data(:,1),2) = data(:,2)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Identification 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by