Creating a table with missing endpoints
1 次查看(过去 30 天)
显示 更早的评论
Hi, consider the matrix below:
732315 108 1.9193000 1.9193000 1.9193000 1.9193000
732315 113 1.9193000 1.9193000 1.9060000 1.9060000
732315 114 1.9058000 1.9058000 1.9058000 1.9058000
732315 115 1.9060000 1.9061000 1.9060000 1.9060000
I want to transform the matrix into the following:
732315 108 1.9193000 1.9193000 1.9193000 1.9193000
732315 109 NaN NaN NaN NaN
732315 110 NaN NaN NaN NaN
732315 111 NaN NaN NaN NaN
732315 112 NaN NaN NaN NaN
732315 113 1.9193000 1.9193000 1.9060000 1.9060000
732315 114 1.9058000 1.9058000 1.9058000 1.9058000
732315 115 1.9060000 1.9061000 1.9060000 1.9060000
Any ideas how? thanks
0 个评论
采纳的回答
Peter Perkins
2018-4-6
Those look suspiciously like datenums, circa 2005. I'm gonna take a wild guess that 108 is 01:08. I might be completely wrong. If I'm not, use a timetable, and retime:
>> X = [732315 108 1.9193000 1.9193000 1.9193000 1.9193000
732315 113 1.9193000 1.9193000 1.9060000 1.9060000
732315 114 1.9058000 1.9058000 1.9058000 1.9058000
732315 115 1.9060000 1.9061000 1.9060000 1.9060000];
>> T = array2table(X,'VariableNames',{'Date' 'Time' 'X1' 'X2' 'X3' 'X4'});
>> T.Date = datetime(T.Date,'ConvertFrom','datenum');
>> T.Time = hours(floor(T.Time/100)) + minutes(mod(T.Time,100));
>> T.TimeStamp = T.Date + T.Time;
>> T.Date = []; T.Time = [];
>> TT = table2timetable(T)
TT =
4×4 timetable
TimeStamp X1 X2 X3 X4
____________________ ______ ______ ______ ______
03-Jan-2005 01:08:00 1.9193 1.9193 1.9193 1.9193
03-Jan-2005 01:13:00 1.9193 1.9193 1.906 1.906
03-Jan-2005 01:14:00 1.9058 1.9058 1.9058 1.9058
03-Jan-2005 01:15:00 1.906 1.9061 1.906 1.906
>> TT = retime(TT,'minutely')
TT =
8×4 timetable
TimeStamp X1 X2 X3 X4
____________________ ______ ______ ______ ______
03-Jan-2005 01:08:00 1.9193 1.9193 1.9193 1.9193
03-Jan-2005 01:09:00 NaN NaN NaN NaN
03-Jan-2005 01:10:00 NaN NaN NaN NaN
03-Jan-2005 01:11:00 NaN NaN NaN NaN
03-Jan-2005 01:12:00 NaN NaN NaN NaN
03-Jan-2005 01:13:00 1.9193 1.9193 1.906 1.906
03-Jan-2005 01:14:00 1.9058 1.9058 1.9058 1.9058
03-Jan-2005 01:15:00 1.906 1.9061 1.906 1.906
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Descriptive Statistics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!