Jenya
Jenya

Reputation: 1

interpolate missing values ( with dates as sample points) in matlab

I am new to Matlab, stuck with understanding data types(especially cell), probably there is an elegant solution I do not know about.

I have a cell which contains other cells with dates:

30/09/2005
30/12/2005
...
30/09/2016

I have also a cell with cells containing corresponding values:

1
5
...
3

I want to interpolate those values for all days/ or working days( better for me). What I have been thinking to do is:

  1. use datenum to receive numbers corresponding to the dates;
  2. plug these dates( now numbers), corresponding values, and all dates( now numbers) in between them, into interp1.

Seemed a good plan but function

datenum('30/12/2005')  = 13297
datenum('30/09/2016')  = 13217

gives numbers which can not be used as earlier date is bigger than later one.

Upvotes: 0

Views: 55

Answers (1)

pablo_worker
pablo_worker

Reputation: 1122

You can add any number of days to a datetime.

t = datetime('now') + days(1);

In addition it can give you the amount of days of a duration. Hence:

t0 = datetime('30/09/2005');
tEnd = datetime('30/09/2016');
durationInDays = days(tEnd - t0);
myDates(0) = t0;
for i = 2:durationInDays
   myDates(i) = myDates(i-1) + days(1);
end

Upvotes: 0

Related Questions