how to read a text file as datetime input?
37 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Andi
am 14 Okt. 2022
Kommentiert: Walter Roberson
am 14 Okt. 2022
Hi everyone,
I have a text file with tiem date format YYYY-MM-DD HH:MM:SS. I want to load it and convert it to datenum. Here is what i attempt so far. (data attached)
cd_ev=readmatrix('tt.txt'); % file attached
%Or
t = load('tt.txt','InputFormat','yyyy-mm-dd HH:mm:ss')
%or
rr=readtable('tt.txt', 'Format','yyyy_mm_dd/dd hh:mm:ss');
None of the above serve fro my purpsoe.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 14 Okt. 2022
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1156138/tt.txt';
t1 = readtable(filename, 'ReadVariableNames', false);
t1.Properties.VariableNames{1} = 'Date';
t1.Date.Format = 'yyyy_MM_dd/dd HH:mm:ss'; %MM for month, HH for 24 hour hour
%verify
t1.Date(1:5)
I am having trouble thinking of a good reason to repeat the day like you asked to.
7 Kommentare
Walter Roberson
am 14 Okt. 2022
addtodate is specifically designed to only accept scalar datenum. b=cand_ev(:,jj); selected a vector of datenum entries, so addtodate(b) failed.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!