Error when using interpolation method
조회 수: 6 (최근 30일)
이전 댓글 표시
Dears,
I have a dataset, includes variables serial, year, month, day, second, and price. I want to calculate the 5 minute frequency, using last tick interpolation. When I reaech to the last step, the serial numbers are changed. The codes here are provided by Star Strider.
T1 = readtable('Data.txt');
% (1) is the serial, (2) year, (3) month, (4) days, (5) time in seconds, and (6) price
T1.Properties.VariableNames = {'serial','year','month','day','seconds','price'}
% T1(end-4:end,:)
DT = datetime(T1{:,[2 3 4]}) + seconds(T1{:,5});
T2 = table(DT,T1{:,1},T1{:,6}, 'VariableNames',{'time','serial','price'})
TT2 = table2timetable(T2);
TT2 = retime(TT2,'regular','linear','Timestep',minutes(5))
A simple and results that I got is attached. Could you guide me to get the code accurately.
댓글 수: 6
Star Strider
2023년 10월 28일
What calculation is necessary to produce the result you want?
I suspect that whatever calculation is is being appliied to the price is being applied to the serial numbers as well, and that is the reason they are changing. The serial numbers probably only need to be interpolated to match the five-minute intervals, and not have any calculations applied to them.
채택된 답변
Star Strider
2023년 10월 28일
편집: Star Strider
2023년 10월 28일
The serial numbers change position because timetable arrays require that the time vector be the first column, regardless of how the original table was constructed.
The serial numbers themselves do not change. (If they were included in the computations, one approach would simply be to remove them, calculate the timetable, and then re-insert them afterwards, interpolated separately to create an appropriate lrow size. However here they are simply interpolated, since that is all this code does.)
Example —
T1 = readtable('Data.txt');
% (1) is the serial, (2) year, (3) month, (4) days, (5) time in seconds, and (6) price
T1.Properties.VariableNames = {'serial','year','month','day','seconds','price'}
% T1(end-4:end,:)
DT = datetime(T1{:,[2 3 4]}) + seconds(T1{:,5});
% T2 = table(DT,T1{:,1},T1{:,6}, 'VariableNames',{'time','serial','price'})
T2 = table(T1{:,1},DT,T1{:,6}, 'VariableNames',{'serial','time','price'})
T2(end-4:end,:)
TT2 = table2timetable(T2)
TT2 = retime(TT2,'regular','linear','Timestep',minutes(5))
TT2(end-4:end,:)
T3 = readtable('Result.txt') % Second File
T3(end-4:end,:)
Time = datetime(T3.Var1, 'InputFormat','''''dd-MMM-yyyy') + timeofday(datetime(T3.Var2,'InputFormat','HH:mm:ss'''''));
T3 = removevars(T3,[1 2]);
T3 = addvars(T3, Time,'Before','Var3')
T3(end-4:end,:)
The second file (‘Result.txt’) appears to be entirely different form the first. The variables are not defined, so I have no idea what they are.
.
댓글 수: 6
Star Strider
2023년 10월 29일
Thank you!
The last tick would be:
Last = T2(end,:)
or:
Last = TT2(end,:)
depending on what you want.
The same approach works for any of the other table or timetable arrays.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
