Effacer les filtres
Effacer les filtres

Converting string cell array to dates

1 vue (au cours des 30 derniers jours)
Luc
Luc le 24 Nov 2016
Commenté : dpb le 30 Nov 2016
Hi,
I need to upload a large (100mb)comma separated .dat file in matlab 2008b. The first column of the file represents the date and time (yyyy-mm-dd HH:MM:SS.S). When I use the code below, the data upload fine and the first column comes out as "yyyy-mm-dd HH:MM:SS.S" in the cells. I am trying to convert this to serial dates using datenum? What I've tried so far resulted in this error message:
??? Error using ==> datenum at 174
DATENUM failed.
Error in ==> Load_and_graph_V5 at 6
Is the problem related to the " " at the begining and the end of the date?
datenum(T{1},formatIn)
fid = fopen('TOA5_TGA.RawData_47_2016_11_21_0000.dat', 'r');
T = textscan(fid, '%s%f%f%f%f%f%f%f%f%f%f%f%f%f', 'Delimiter',',','HeaderLines',4);
fclose(fid);
formatIn = 'yyyy-mm-dd HH:MM:SS.S';
datenum(T{1},formatIn)
Any help or suggestions would be appreciated!
Thanks
  13 commentaires
Luc
Luc le 30 Nov 2016
Great! It works now. Thanks everyone for your help!
dpb
dpb le 30 Nov 2016
I'll just note that perhaps could fix the problem in the place where the file was created initially to ensure consistent format.
I've bit^h^h^h complained to TMW previously over how fragile the time conversion format parsing is--it seems to me there should be no reason for it to fail there; the value is unambiguous. It'd be a reasonable enhancement request to suggest it not fail or, if that really is difficult owing to the way the C-based i/o formatting strings function, at least echo the line that caused the problem in the error.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Time Series Objects dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by