Creating a table with missing endpoints

1 回表示 (過去 30 日間)
AA
AA 2018 年 4 月 5 日
コメント済み: AA 2018 年 4 月 6 日
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

採用された回答

Peter Perkins
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
  1 件のコメント
AA
AA 2018 年 4 月 6 日
wow thanks a lot. it worked!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by