MATLAB: The most effective way to use interp1 command in matlab with two columns

interpolation

I have two columns (same size) that I have to interpolate in Matlab. First column is a vector of time in hours (9.5, 9.6 9.73 10.13 etc…) and the other column are stock prices associated to each element of the column "time in hours". I also have third column with daily dates.
I wish to have some prices that are associated with each 15min, 30min, 45min, and 1hour (60min) that are missing in my price vector. And therefore, thee elements (15,30,45min and 60min) are also missing in my column of time per hours. I intend to use this command:
interp_prices = interp1(time, prices, 0:0.25:max(time));
But can I run the interp1 command by day? By that I mean, in addition to my column time and prices I have days and I don't want to interpolate between days… that is between say 16.5hours (calculated from midnight) to 9hours (am). Thanks!

Best Answer

I solved my problem this way:
% This datenum vector matches A. I'm assuming they're already sorted by date and time
At = datenum(num2str(A_dates), 'yyyymmdd') + datenum(0, 0, 0, A_hours, 0, 0);
incr = datenum(0, 0, 0, 0.25, 0, 0); % 0.25 hour
t = (At(1):incr:At(end)).'; % Full timespan of dataset, in 0.25 hour increments
frac_hours = 24*(t - floor(t)); % Fractional hours into the day
t_business_day = t((frac_hours > 9.4) & (frac_hours < 16.1)); % Time vector only where you want it
P = interp1(At, A_prices, t_business_day);