I wrote some code that matches up observational data (data recorded every 10 minutes for 15 years) that is occasionally missing a timestep, or multiple timesteps, with a complete, ideal time series. The problem is that it takes way too long, and I'm betting there's a better way to do this that I just haven't thought of.
Here's the code:
%Creates an empty array that will be filled in with observed meteorological data
%values
ideal_obs = zeros(766945,3);%For loop that fills in meteorological data for every timestep in the time series
for m = 1:766945 %This m iterates over every row of date_time_index
for r = 1:size(time_obs,1) % r iterates over 'n' rows of observed time data
if isequal(date_time_index(m,1),time_obs(r,1)) == 1 ideal_obs(m,:) = raw_data(r,1:3); break elseif isequal(date_time_index(m,1),time_obs(r,1)) == 0 if r == size(time_obs,1) ideal_obs(m,1:3) = NaN; end continue else disp('Derp') end end end
The idea is that my program will iterate through my ideal time series, and will attempt to import data from my observational dataset for every time step (every 10-minute period) in the idealized time series.
For missing observations, NaN is used. This way, I have a complete time series and can see where I have missing data, and can later decide how to deal with it.
The code works. I ran it on a small subset of my data. The problem is, I tried running it on my complete dataset, and it ran all night and hasn't finished yet. I'm hoping someone might be able to suggest a faster way to accomplish this task. In Excel I was using Vlookup() and it finished pretty quickly…
Best Answer