Convert text file to Excel file with dates in the correct format?

1 Ansicht (letzte 30 Tage)
I'm trying to get my code (below) to convert FDATA.TXT (attached) to an Excel File (attached). Once in Excel, the dates all have "0:00" after them, and I want to get rid of these 0:00 times and just have the dates shown in Excel.
The text file is generated from a SD card Arduino coded in C++ (I think?). Thanks so much!
close all
clc
T = readtable('FDATA.TXT'); % read text file
T.Var3.Format = 'MM/dd/yyyy'; % I tried adjusting the date format
writetable(T,'Initial Table Data.xlsx') % convert to Excel file
  3 Kommentare
Natalie Schmidt
Natalie Schmidt am 14 Aug. 2021
I've attached a screenshot- it's in the third column. Thanks so much!
Walter Roberson
Walter Roberson am 14 Aug. 2021
Is it mandatory that the Excel output have 3 columns? It would make more sense to treat the second input column as a duration to be added to the third input column as a datetime, giving you a result that is a unified datatime entry that has date and time together as a single column.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Simon Chan
Simon Chan am 14 Aug. 2021
You may change it to a string format and write to an excel file.
clear; clc;
T=readtable('FDATA.TXT');
T.Var3=datestr(T.Var3,'mm/dd/yyyy');
writetable(T,'Initial Table Data.xlsx');
  3 Kommentare
Natalie Schmidt
Natalie Schmidt am 25 Aug. 2021
Thank you so much! While it worked for lines 1-95 in Excel, starting in line 96, the dates say "######" in Excel. (This is because the dates start repeating again in line 96 (starting again w/ 7/1/21- I don't know why). How can I fix that?
Simon Chan
Simon Chan am 26 Aug. 2021
Could you upload the file once again including line 96?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by