The most effective way to use interp1 command in matlab with two columns
Mostrar comentarios más antiguos
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!
Respuesta aceptada
Más respuestas (2)
per isakson
el 7 de Jun. de 2012
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 );
1 comentario
Charles Martineau
el 7 de Jun. de 2012
Charles Martineau
el 7 de Jun. de 2012
0 votos
1 comentario
per isakson
el 7 de Jun. de 2012
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?
Categorías
Más información sobre Dates and Time en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!