
outerjoin between timetables changing the time format
8 views (last 30 days)
Show older comments
Shuvashish Roy
on 4 Nov 2020
Commented: Peter Perkins
on 20 Nov 2020
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')
Accepted Answer
Adam Danz
on 4 Nov 2020
Edited: Adam Danz
on 4 Nov 2020
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 Comments
Adam Danz
on 4 Nov 2020
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
on 20 Nov 2020
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.
More Answers (0)
See Also
Categories
Find more on Standard File Formats in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!