Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting Matlab's datenum format to Python
    primarykey
    data
    text
    <p>I just started moving from Matlab to Python 2.7 and I have some trouble reading my .mat-files. Time information is stored in Matlab's datenum format. For those who are not familiar with it:</p> <blockquote> <p>A serial date number represents a calendar date as the number of days that has passed since a fixed base date. In MATLAB, serial date number 1 is January 1, 0000.</p> <p>MATLAB also uses serial time to represent fractions of days beginning at midnight; for example, 6 p.m. equals 0.75 serial days. So the string '31-Oct-2003, 6:00 PM' in MATLAB is date number 731885.75.</p> <p>(taken from the Matlab documentation)</p> </blockquote> <p>I would like to convert this to Pythons time format and I found <a href="http://sociograph.blogspot.de/2011/04/how-to-avoid-gotcha-when-converting.html" rel="nofollow noreferrer">this tutorial</a>. In short, the author states that</p> <blockquote> <p>If you parse this using python's <code>datetime.fromordinal(731965.04835648148)</code> then the result might look reasonable [...]</p> </blockquote> <p>(before any further conversions), which doesn't work for me, since datetime.fromordinal expects an integer:</p> <pre><code>&gt;&gt;&gt; datetime.fromordinal(731965.04835648148) Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: integer argument expected, got float </code></pre> <p>While I could just round them down for daily data, I actually need to import minutely time series. Does anyone have a solution for this problem? I would like to avoid reformatting my .mat files since there's a lot of them and my colleagues need to work with them as well.</p> <p>If it helps, <a href="https://stackoverflow.com/questions/8776414/python-datetime-to-matlab-datenum">someone else asked for the other way round</a>. Sadly, I'm too new to Python to really understand what is happening there.</p> <p>/edit (2012-11-01): This has been fixed in the tutorial posted above.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload