Filling gaps in time series with Nan

2 visualizzazioni (ultimi 30 giorni)
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!

Risposta accettata

Fabio Freschi
Fabio Freschi il 10 Set 2019
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)

Più risposte (0)

Categorie

Scopri di più su Polynomials in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by