0
votes

I have the following dataset:

27/10/2014,11:45:00,231
27/10/2014,12:00:00,229
27/10/2014,12:15:00,NaN
27/10/2014,12:30:00,NaN
27/10/2014,12:45:00,227
27/10/2014,13:00:00,225
27/10/2014,13:15:00,NaN
27/10/2014,13:30:00,NaN
27/10/2014,13:45:00,222
27/10/2014,14:00:00,221
27/10/2014,14:15:00,NaN
27/10/2014,14:30:00,NaN
27/10/2014,14:45:00,219
27/10/2014,15:00:00,218
27/10/2014,15:15:00,NaN
27/10/2014,15:30:00,NaN
27/10/2014,15:45:00,214

I need to interpolate the missing data using interp1 command:

date_string = strcat (dados.textdata(2:end,2),{' '}, dados.textdata(2:end,3));
 xdate = datenum (date_string, 'dd/mm/yyyy HH:MM:SS');
 xi = (1 :length(xdate))';
 yi = interp1 (xdate,dados.data,xi);

However, yi returns only NaN's.

How can I plot interpolated values?

1
Remove the NaNs from the input. - AnonSubmitter85

1 Answers

3
votes

As @AnonSubmitter85 mentioned, you have first to remove the nan from the input. This can be done by:

r = ~isnan(dados.data);
yi = interp1(xdate(r),dados.data(r),xi);

However, you probably also want to use xdate rather than xi as argument for the interpolated data.

yi = interp1(xdate(r),dados.data(r),xdate);

The output is thenenter image description here