Customized datetime format within table
5 ビュー (過去 30 日間)
古いコメントを表示
Hi all,
I am trying to compare 2 tables (for both 1st column is datetime, others are numbers). I am trying to find the common timeperiod between those 2 tables. Unfortunately, days are not the same. My original idea is to convert dates into string and look for matching strings between both tables.
Question:
I am a beginner at Matlab, is there a better way to do it? If not, is there an elegant way to get rid of the 2 loops?
Here is the script for the transformation shown in the workspace
------------------------------------------------------------
A1 = readtable(file_name,'VariableNamingRule','preserve'); clc;
B1 = readtable('Independant variables.xlsx');
for i = 1:height(A1)
A2{i,1} = extractBetween(datestr(A1{i,1}),4,11);
end
for j = 1:height(B1)
B2{j,1} = extractBetween(datestr(B1{j,1}),4,11);
end
------------------------------------------------------------
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1558324/image.png)
Thanks and best regards,
3 件のコメント
採用された回答
その他の回答 (1 件)
Peter Perkins
2023 年 12 月 4 日
Vic, I think you want synchronize.
tt1 = timetable([1;2;3;4;5],RowTimes=datetime(2023,1:5,1))
tt2 = timetable([6;7;8;9;10],RowTimes=datetime(2023,1:5,[31 28 31 30 31]))
tt3 = synchronize(tt1,tt2,"monthly","firstvalue");
tt3.Time.Format = "MMM-uuuu"
If you don't want the two timetables joined together, use retime on the second one with the first one's time vector as the target row times.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Timetables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!