MATLAB: Filling gaps in time series with Nan

big datadatafiltertime series

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!

Best Answer

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)