how to interpolate data to a 5 minute time series instead of 15 minute when data is in date,month,year time and ins't unique in matlab

Assuming you have data stored in times and values matrices in Matlab where times is not unique, but it represents the time and date data, you can interpolate the data to a 5 minute time series instead of 15 minute using the following steps:

  1. Convert the times matrix to serial date numbers using datenum function.

  2. Create a new time vector with a 5-minute interval using min function, floor function, and datenum function. This new time vector will be used as the basis for the 5-minute time series.

main.m
t_start = floor(min(times)*24*60)/24/60; % starting time rounded down to 5 minute
t_end = floor(max(times)*24*60)/24/60; % ending time rounded down to 5 minute
new_times = (t_start:(5/1440):t_end)'; % new time vector with 5 minute interval
240 chars
4 lines
  1. Interpolate the values matrix to the new time vector using interp1 function.
main.m
new_values = interp1(times, values, new_times);
48 chars
2 lines
  1. Convert the new time vector back to a date format using datestr function.
main.m
new_dates = datestr(new_times, 'dd/mm/yyyy HH:MM');
52 chars
2 lines

Now new_dates will be a column vector of dates corresponding to interpolated data in new_values.

gistlibby LogSnag