How do I manipulate data from a csv datafile containing date, time and number data?
Mostrar comentarios más antiguos
This sounds intuitively easy but it has me puzzled. Columns 1 and 2 contain datetime formatted data, with column 3 double precision numerical. I can import the data using READTABLE with no apparent problem but subsequent manipulation continues to fall over. Is it best to split this into three separate (n x 1) arrays, or can I work with the data as one (n x 3) matrix? My routine is to read in the data, extract portions of the data (e.g. 600 rows) and then statistically analyse the values of the third column. The routine was working fine until I exceeded 24 hours of data, when it then ran into ambiguity due to ambiguous data type. I continue to run into a problem during subsequent code using DATEVEC, which produces an error message regarding data type, and using TABLE2ARRAY which also produces a data-type error. I am using R2016b. I am pretty new to Matlab and have attached a small sample input data. Cheers Bob
Respuesta aceptada
Más respuestas (1)
Peter Perkins
el 20 de Jun. de 2017
1 voto
Your file has date and time in two separate fields. Depending on what version of MATLAB you're using, the table that readtable returns may already have datetimes in it, or it might have text. It sounds like the former. If that's correct, what will happen is that readtable will read the second column of your spreadsheet as datetimes, filling in "today" as the date portion.
You say,
"The routine was working fine until I exceeded 24 hours of data, when it then ran into ambiguity due to ambiguous data type."
but your sample file doesn't have an example of that, it's all on one day, all on the same hour. And it's not at all clear what you mean by ambiguous. I can only guess.
My guess is that you mean that while your date stamps run over several days, your time-only stamps seem not to. That's because of what I've described above. Try this: call timeofday on the second variable in the table that readtable returns. That creates a duration. Mow add that duration to the first var in the table. You now have the datetimestamps that I think you want. You may have to adjust the display format to show the time portion, but I think that will happen automatically.
Hope this helps.
1 comentario
Robert Fitzell
el 21 de Jun. de 2017
Categorías
Más información sobre Calendar en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!