outerjoin between timetables changing the time format

8 次查看(过去 30 天)
Hi, I am attaching the variable.mat that contains g8067525, g8072050 table variables. I was trying to join them (after filling the time series gaps with NaNs) using outerjoin function. However, it changes the time format from "24-Aug-2017 00:00:00" to "24-Aug-2017" in the output file. Basically it is ignoring the hh:mm:ss part. I highly appreciate your help to make it showing the full time format. Thanks a lot.
t1 = datetime(2017,8,24,0,0,0); % start of simulation/usgs gage reading
t2 = datetime(2017,9,1,0,0,0); % end of simulation/usgs age reading
t3 = t1:minutes(15):t2; % 15 minutes interval
t=t3'; % make it column vector
x={g8067525, g8072050}
TT=timetable();
for k=1:length(x)
x1=table2timetable(x{k});
x2=retime(x1,t);
TT=outerjoin(TT,x2);
end
T= timetable2table(TT);
writetable(T,'usgs.dat','Delimiter','\t')
  6 个评论
Adam Danz
Adam Danz 2020-11-18
编辑:Adam Danz 2020-11-18
You can set the format of the time column named "Time" in a timetable TT using
TT.Time.Format = 'dd-MMM-uuuu HH:mm:ss'; % Or whatever format you want to use

请先登录,再进行评论。

采纳的回答

Adam Danz
Adam Danz 2020-11-4
编辑:Adam Danz 2020-11-4
The problem could not be reproduced in r2020b suggesting that his has been fixed since r2017a.
" would you please tell me how to align the headers with the column values."
If this file will be read back into matlab (or any other program that expects a constant delimiter) you should not align the columns.
If you want to do this for better human-readability, I suggest you write it to a spreadsheet instead of a text file.
Nevertheless, one way to control the position of the headers relative to the data columns is by adding spaces before or after the header names. But this can get messy and the result can differ between text editors. For example, to shift the header for T.t all the way to the left, you just need to add 19 spaces to the right of the label since "24-Aug-2017 00:00:00" has 20 spaces.
% char(32) results in a space character " ".
T.Properties.VariableNames{1} = [T.Properties.VariableNames{1},char(ones(1,19)*32)];
When this is printed to the Matlab console,
When I open that in notepad++,
When I open it in Matlab's editor,
When I open it in Microsoft's Notpad,
  3 个评论
Adam Danz
Adam Danz 2020-11-4
Glad I could help.
Of course you could convert the entire table to string values which would make it relatively easy to align the columns within a text file.
Peter Perkins
Peter Perkins 2020-11-20
Nice trick, but "by adding spaces before or after the header names" is supported only recently, IIRC R2019b. Prior to that, spaces were stripped off.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Standard File Formats 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by