Filling gaps in time series with Nan

2 vues (au cours des 30 derniers jours)
Jaehwi Bong
Jaehwi Bong le 10 Sep 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!

Réponse acceptée

Fabio Freschi
Fabio Freschi le 10 Sep 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)

Plus de réponses (0)

Catégories

En savoir plus sur Polynomials dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by