Regular time intervals of time series without interpolation

4 次查看(过去 30 天)
Hello, I have the data of a following time series :
Time(s) Value
0 12 15
0.14 8
0.15 10
0.19 11
1.2 12
1.3 13
2.4 14
2.8 17
3.1 15
3.5 25
4.1 14
4.4 20
5.8 11
5.9 6
I want to get these data on regular time intervals (each 1 s) without interpolation. How I can achieve this task under matlab?

采纳的回答

Walter Roberson
Walter Roberson 2017-3-19
You do not have a regular csv file. You need to read the data in first:
filecontent = fileread('Book1.csv');
data = str2double(regexp(regexprep(filecontent,{',', ';'},{'.', ','}), '[,\r\n]+', 'split'));
if mod(length(data),2) ~= 0; data(end) = []; end %a trailing empty line will have become a NaN, get rid of it
data = reshape(data,2,[]).';
Now, if you have R2016b or later:
tt = timetable(data(:,2), 'RowTimes', seconds(data(:,1)));
After that you can
retime(tt,'secondly', 'mean')
or
retime(tt,'secondly', 'sum')
as appropriate for your needs.
  3 个评论
Walter Roberson
Walter Roberson 2017-3-20
编辑:Walter Roberson 2017-3-20
timetables do not exist in R2015a, and retime() does not exist either.
Do you want the sum for every second, or do you want the mean for every second, or something else?
In the attached .mat, the variable tmean is the average of each 1 second interval for the Book2 data, and the variable tsum is the total of each 1 second's values.

请先登录,再进行评论。

更多回答(1 个)

John D'Errico
John D'Errico 2017-3-19
编辑:John D'Errico 2017-3-19
You cannot do so.
You want to interpolate a set of points. But you refuse to use interpolation? Sorry, but that makes no sense at all. I suppose we can make up some other name for the process, even though it still does the same thing as interpolation. I think you need to use magic here. Sadly, magic is already used to generate magic squares of order n. :)
Seriously, however you want to name the problem, you still need to interpolate the data.
Perhaps you were told you cannot use the interpolation tools in MATLAB like spline or interp1. You still need to interpolate. A rose by any other name would smell as sweet.
Just do linear interpolation. This is very clearly homework. I will not do your homework, as that is there for you to do, and you will learn by so doing.
You can easily find the formula for linear interpolation online. Google is your friend. Personally, I'd just search for the term "interpolation wiki" that will pop up this site on top of the list. In there you will find linear interpolation described. Or, you can be more demanding and search for a "linear interpolation algorithm". There are lots of hits for that online too, but the algorithm is pretty basic.
A simple loop will suffice, although vectorized solutions are not that difficult. For homework, I'd suggest that you don't bother with the vectorization unless your MATLAB skills are up to the task. For each point in question, you locate the pair of points on the real line (time) that bracket the point to be interpolated. (Oh dear, I used the bad word!) Then apply the linear interpolation formula that you have found.
  3 个评论
per isakson
per isakson 2017-3-19
编辑:per isakson 2017-3-19
"are larger, so I think an interpolation is not the right solution" &nbsp To me that sounds strange. Please, elaborate.
John D'Errico
John D'Errico 2017-3-20
But we cannot know why you have decided that interpolation is not meaningful here. Why do you think that the numbers being "larger" should imply that interpolation is right or not?
As well, if you know something about the data that you have not bothered to tell us, then how can we know how to solve the problem?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by