Plotting Date Time data being read from an excel table
Mostrar comentarios más antiguos
I'm trying to read an excel file where the format of the date/time data is: '01.10. 07:30' ('dd.mm. HH:MM')
I can read the raw text data into MATLAB using:
[num,text,both] = xlsread(filename,sheet,'B:B');
But I then try to convert this into date number format using:
DateTime = datenum(date,'dd.mm. HH:MM');
However I'm getting the following error:
Error using datenum (line 188)
DATENUM failed.
Error in WeatehrInfoGraphs (line 9)
DateTime = datenum(date,'dd.mm. HH:MM');
Caused by:
Error using dtstr2dtnummx
Failed to convert from text to date number.
1 comentario
Ieuan Price Davies
el 10 de Nov. de 2020
Respuestas (1)
Cris LaPierre
el 10 de Nov. de 2020
0 votos
Then, when you plot, your datetimes will appear in your axis. If you need to adjust the format, use the xtickformat function.
5 comentarios
Ieuan Price Davies
el 10 de Nov. de 2020
Cris LaPierre
el 10 de Nov. de 2020
Editada: Cris LaPierre
el 10 de Nov. de 2020
Can you attach a sample dataset? You can use the paperclip icon to do so. Readtable is pretty good at autodetecting data type, so I might do something like this:
opts = detectImportOptions(filename);
data = readtable(filename,opts);
Ieuan Price Davies
el 10 de Nov. de 2020
Cris LaPierre
el 10 de Nov. de 2020
Editada: Cris LaPierre
el 10 de Nov. de 2020
Ok, here's how I would load the spreadsheet.
opts = detectImportOptions("ZanzibarConditions.xlsx");
opts = setvartype(opts,"Date","datetime");
opts = setvaropts(opts,"Date",'InputFormat','MM.dd. HH:mm');
% By default, variable names are the column headers. That can result in a warning (see below)
% These can be changed using the syntax below (uncomment & provide name for each column).
% opts.VariableNames = ["Hour","Date","NDI","DIAS",...];
data = readtable("ZanzibarConditions.xlsx",opts)
With your data in a table, you can access the individual variables using dot notation.
data.Date
Peter Perkins
el 20 de Nov. de 2020
In addition to what Cris sys, you might find it convenient to convert that table to a timetable using table2timetable.
Categorías
Más información sobre Time Series Objects 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!