The most effective way to use interp1 command in matlab with two columns
显示 更早的评论
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!
采纳的回答
更多回答(2 个)
per isakson
2012-6-7
Something like
new_times = 0:0.25:max(time);
day_hour = rem( new_times, 24 );
new_times( day_hour <= 8.9 | day_hour >= 16.6 ) = [];
interp_prices = interp1( time, prices, new_times );
Charles Martineau
2012-6-7
0 个投票
1 个评论
per isakson
2012-6-7
The values time must be unique. Which price do you want to use, mean, max, min, first, last?
May three or more identical time values occur?
类别
在 帮助中心 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!