Error when using interpolation method
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Emad
el 28 de Oct. de 2023
Comentada: Star Strider
el 29 de Oct. de 2023
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 comentarios
Star Strider
el 28 de Oct. de 2023
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.
Respuesta aceptada
Star Strider
el 28 de Oct. de 2023
Editada: Star Strider
el 28 de Oct. de 2023
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 comentarios
Star Strider
el 29 de Oct. de 2023
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Multirate Signal Processing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
