Filling gaps in time series with Nan

2 visualizaciones (últimos 30 días)
Jaehwi Bong
Jaehwi Bong el 10 de Sept. de 2019
Respondida: Fabio Freschi el 10 de Sept. de 2019
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!

Respuesta aceptada

Fabio Freschi
Fabio Freschi el 10 de Sept. de 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)

Más respuestas (0)

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by