Borrar filtros
Borrar filtros

Converting date range from numeric to date format in mat file

7 visualizaciones (últimos 30 días)
Ameer Fahmi
Ameer Fahmi el 27 de Jun. de 2019
Editada: dpb el 30 de Jun. de 2019
I have a mat file in which I store the data to use for analysis when needed, I wanted to past a data from excel to the mat file
This is the data I need to copy to the mat file from excel
date Inflows HPI
6/30/1985' -738.4928374 -1.376979203
9/30/1985' -149.8324882 -1.318316639
12/30/1985' -389.9021275 -1.404933598
3/30/1986' -1250.503701 -0.137879304
6/30/1986' -944.0048226 -3.060762411
9/30/1986' -64.68902275 0.169427825
12/30/1986' -278.1197318 0.049207493
3/30/1987' -507.793333 4.174160222
However, when I past the data, the date column is taken as numeric as seen below
'date' 'Inflows' 'HPI'
0.000151133501259446 -149.832488200000 -1.31831663900000
0.000201511335012594 -389.902127500000 -1.40493359800000
5.03524672708963e-05 -1250.50370100000 -0.137879304000000
0.000100704934541793 -944.004822600000 -3.06076241100000
0.000151057401812689 -64.6890227500000 0.169427825000000
0.000201409869083585 -278.119731800000 0.0492074930000000
5.03271263210871e-05 -507.793333000000 4.17416022200000
0.000100654252642174 -317.350932300000 3.98837463000000
0.000150981378963261 -289.777479600000 2.87872744700000
Is there any way to convert the date column from numeric to date format
  12 comentarios
Ameer Fahmi
Ameer Fahmi el 30 de Jun. de 2019
I had to do it, even though for me didn't make any sense, because the functions in the m-file code I'm using use the dates as numeric, and the code works fine with it.
dpb
dpb el 30 de Jun. de 2019
Still, if you have to read the Excel file for the data, it's already parsed as datetime ignoring the header so just convert that representation to datenum directly instead of parsing the same data over yet again...
Or, of course, fix the function itself to use the more better datetime instead... :)

Iniciar sesión para comentar.

Respuestas (1)

Steven Lord
Steven Lord el 28 de Jun. de 2019
If you want to store date and time data in MATLAB I strongly recommend storing it as a datetime array or in a timetable with a datetime array as the RowTimes property of the timetable. Once you have the data in a form that stores your data as datetime use something like writetable (introduced in release R2013a), writematrix (R2019a) or writetimetable (R2019a) or convert the datetime to an Excel serial date number with exceltime.
  1 comentario
Ameer Fahmi
Ameer Fahmi el 28 de Jun. de 2019
Editada: Ameer Fahmi el 28 de Jun. de 2019
I tried what you've seggested, then I pasted the data I imported in form of timetable (SAdata1) to the GC mat file
GC.y=SAdata1;
But I had the same problem when trying to seperate the date column using the datenum function as follows
data=GC.y;
date=datenum(cell2mat(data(2:end,1)),'mm/dd/yyyy');
But this time I got different error
Error using cell2mat (line 42)
Subscripting a table using linear indexing (one subscript) or multidimensional indexing (three or more
subscripts) is not supported. Use a row subscript and a variable subscript.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by