Make unequally spaced data, equally spaced
Show older comments
Hello all,
I have the hourly temperature history for a long period of time (100k datapoints) for several locations. For easier data manipulation I would like 24 measurements for each day. However the data I have, has sometimes either 2-4 measurements within the same hour or inversely there are some hours without any measurement.
The time spamps are of the format 200001010000 (YEARMODAHRMN). I would like to ask you if you can think or have any script that could do the interpolation between adjacent data so that finally I end up with data points that are equally spaced.
Thank you in advance.
3 Comments
Jan
on 28 Apr 2015
Please provide a meaningful example of the data and explain, what you have tried so far.
Star Strider
on 28 Apr 2015
Are the timestamps imported as integer (numeric) or string variables?
Konstantinos Belivanis
on 30 Apr 2015
Accepted Answer
More Answers (1)
Perhaps this is obvious, but
datenum(date,'yyyymmddhhMM');
where "date" is a char variable containing your timestamp, converts the date into a number. E.g.
datenum('200001010000','yyyymmddhhMM')
Gives
730486
and
dd=['200001010000';'200101010000']
datenum(dd,'yyyymmddhhMM')
gives
730486
730852
You can go through your timestamps individually, in a loop, or form a Nx12 matrix of chars and feed it to datenum. Either way you end with a Nx1 vector of numbers representing the timestamps, and you'll have a similar vector containing the corresponding temperatures.
At this point, you can form an equally spaced grid using linspace, and use "interp1" to interpolate your data. You'll have to be a bit careful in selecting the correct number of gridpoints, but that should not be hard.
Type "help function" or "doc function" to summon the documentation for the builtin functions.
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!