Convert from datenum to yymmddHHMMSS

3 views (last 30 days)
I have a large list of dates which I previously converted from yymmddhhmmss format to datenum format using
Now, at the end of a lot of processing, I'd like to reverse this process, to make presentation of my data more readable.
I have tried this:
formatOut='yymmddHHMMSS'; %convert datenum back to original filename format
short_files=datestr(short_files, formatOut);
out=('short_files.csv'); %.csv filename with serialNo
out = sprintf('%s_%d%s',fnm,serialNo,ext);
and while this works in my list of variables, when I export to .csv, the values I get look like this:
1.90704E+11 .

Accepted Answer

Walter Roberson
Walter Roberson on 29 Aug 2019
dlmwrite() assumes that the inputs are numeric unless you specify the 'precision' option with a format code such as '%s'
You should
outfile = fullfile(OutputDirectoryName, out);
fid = fopen(outfile, 'wt');
for K = 1 : size(short_files,1)
fprintf(fid, '%s\n', short_files(K,:));
Or you should skip the problem by using datetime objects and tables and writetable()
Louise Wilson
Louise Wilson on 4 Sep 2019
Hi Walter, I figured it out by just doing this:
short_files=datestr(short_files_list, formatOut);
out=('short_files.csv'); %.csv filename with serialNo
out = sprintf('%s_%d%s',fnm,serialNo,ext);
dlmwrite(fullfile(folder,out),short_files,'delimiter',''); %write output to separate .csv
...this converts the filename back to the format I am interested in and writes to the csv all good.
Thanks for your help

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!

Translated by