I am trying to read Excel sheet. On the same computer, I have different results. What should I do to read Date-time as Date and not a string?
I know that I can change it later on, but I need to have the same code for Octave and Matlab.
Matlab:
[data,header, raw]=xlsread('Mappe1.xlsx');
data =
0 -0.1843 -0.1445
0 -0.1845 -0.1455
0 -0.1833 -0.1461
0 -0.1819 -0.1466
header =
'Stamp' 'R1.1' 'R2.1' 'R2.2'
'24.11.2017 09:41:25' '' '' ''
'24.11.2017 05:41:23' '' '' ''
'24.11.2017 01:41:21' '' '' ''
'23.11.2017 21:41:19' '' '' ''
Octave:
data =
4.3063e+004 0.0000e+000 -1.8434e-001 -1.4451e-001
4.3063e+004 0.0000e+000 -1.8445e-001 -1.4551e-001
4.3063e+004 0.0000e+000 -1.8328e-001 -1.4611e-001
4.3063e+004 0.0000e+000 -1.8186e-001 -1.4661e-001
4.3063e+004 0.0000e+000 -1.8071e-001 -1.4493e-001
4.3063e+004 0.0000e+000 -1.8192e-001 -1.4123e-001
4.3062e+004 0.0000e+000 -1.8348e-001 -1.4165e-001
4.3062e+004 0.0000e+000 -1.8358e-001 -1.4219e-001
4.3062e+004 0.0000e+000 -1.8342e-001 -1.4284e-001
header =
{
[1,1] = Stamp
[1,2] = R1.1
[1,3] = R2.1
[1,4] = R2.2
}
Ensure your Excel data is formatted in Excel as a date, and then load from MATLAB using "basic" mode:
[data,header,raw]=xlsread('Mappe1.xlsx','','','basic');
Firstly the data you show above gives your date format as 24.11.2017 09:41:25
. The dot-separators don't look standard to me, which makes me wonder how they're stored in Excel. I would use a standard format like 2017-11-24 09:41:25
and ensure that Excel recognises them as dates/times. (See here for formats that MATLAB likes).
Doing the above I was able to read in numeric values in MATLAB that look the same as those you requested. Using basic mode will read in the dates as Excel serial numbers (not MATLAB datenums) as documented here.
If you don't use "basic" mode then the MATLAB behaviour depends on the the Excel version installed on your computer (which we don't know). I don't know how Octave works in this case.
Finally, writing code that works in both MATLAB and Octave may not be possible in the simple case (or even not at all). You will have to be prepared to jump through hoops to make this happen. Also I don't claim this will work the same in Octave as I don't have Octave to test!