MATLAB Answers

Linear Interpolation hard task

조회 수: 1(최근 30일)
Sheikh Mohammad Hussain
Sheikh Mohammad Hussain 2021년 6월 6일
답변: Akira Agata 2021년 6월 18일
Ok so i will try to simplify my problem here and explain it. I have some sensor readings of power with corresponding time stamps. An example extract is shown below.
Timestamp Power
2021-04-01 15:07:19 0.0834
2021-04-01 15:08:02 0.0726
2021-04-01 15:08:42 0.0123
2021-04-01 15:09:24 0.0999
As you can see that the sensor data unfortunately has no fixed time interval between data readings.
My goal is to create a new table with a fixed time interval of one minute. In this table the Timestamp will go from 2021-04-01 00:00:00 till
2021-04-01 23:59:00 ( A total of 1440 readings for 24 hours). I have done this part already.
Now comes my question. How to i linearly interpolate the data above to match up with with my new time stamps? The challenge is also to automatically fill in the power readings with '0' on timestamps where no data was recorded.
What i mean to say is, the raw sensor data file dosent start its readings on 2021-04-01 00:00:00, but on a random time of the day,
like 2021-04-01 07:19:51. Thats why i want to automatically fill in power values with 0 when no data is recorded.
Calling out on all MATLAB heros out there to help me. Thanks alot in advance!
Note: I'll attach the real sensor file so you guys can get the feel of the problem.
  댓글 수: 2
Walter Roberson
Walter Roberson 2021년 6월 6일
Consider using a timetable() object and retime()

댓글을 달려면 로그인하십시오.


Akira Agata
Akira Agata 2021년 6월 18일
As @Walter Roberson -san suggested, timetable and retime is the best solution. Please try the following:
TT = readtimetable('_sd_OPV_OPV_1_dp_2021_04_01.csv',...
TT2 = retime(TT,'minutely','linear');

Community Treasure Hunt

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

Start Hunting!

Translated by