How to work with observed dates in the format 'dd/mm/yyyy' imported from Excel into MATLAB.
Ältere Kommentare anzeigen
Hello, please I am trying to import a dataset, which contains observed dates, from excel into MATLAB. The dates are in the format 'dd/mm/yyyy'. Example, 22/01/2021. When I store the column containing the dates under 'Datetime', the data cannot be imported. It can be imported when stored under 'Categorical'. In the latter case, I find it difficult to convert using 'datestr' function. Please, apart from changing the date format in excel before importing (example 22-Jan-2021), is there any other faster way to go about this? Meanwhile, I have thousands of observed dates to work with. Hence converting them 'manually' in excel would be time consumimg. Thanks very much.
4 Kommentare
Cris LaPierre
am 16 Mär. 2021
What version of MATLAB are you using? Are you getting any error message or warning when trying to save as datetime?
The best way to work with this data is to import it directly as a datetime. Can you attach a sample file to your post? Use the paperclip icon.
Victor Lartey
am 21 Mär. 2021
Walter Roberson
am 21 Mär. 2021
filename = 'data_.xlsx';
opt = detectImportOptions(filename);
opt = setvaropt(opt, 3, 'type','datetime');
t = readtable(filename, opt);
Victor Lartey
am 23 Mär. 2021
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Dates and Time finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!