Come si converte un Python datetime
in un Matlab datetnum
?Python datetime su Matlab datum
risposta
per serializzare datetime come una stringa, strftime può essere utilizzato sul lato Python:
import datetime
d = datetime.datetime.now()
print (d.strftime("%d-%b-%Y %H:%M:%S"))
Secondo MatLab docs datenum sa come analizzarlo.
retromarcia cosa è stato fatto here, ho ottenuto:
def datetime2matlabdn(dt):
ord = dt.toordinal()
mdn = dt + timedelta(days = 366)
frac = (dt-datetime(dt.year,dt.month,dt.day,0,0,0)).seconds/(24.0 * 60.0 * 60.0)
return mdn.toordinal() + frac
dovrebbe funzionare con timedelta.microseconds
troppo.
In IDLE:
n = datetime.now()
datetime.datetime (2012, 2, 13, 6, 56, 2, 619000)
datetime2matlabdn (n)
734912.28891203704
in Matlab:
>> datestr (734912,28891203704)
ans = 13-Feb-2012 06:56:02
+1 leggermente fuori tema, ma io avevo fare una conversione simile tra MATLAB 'datenum' e C#' System.DateTime' in una mia vecchia risposta. Oltre alle diverse unità utilizzate internamente, il punto di riferimento nel tempo era anche spento di 366 giorni: http://stackoverflow.com/a/7558811/97160 – Amro
in realtà 'datestr (734912.28891203704, 'mmmm dd, yyyy HH: MM: SS. FFF AM ') 'yields' 13 febbraio 2012 6: 56: 02.000 AM' quindi non conserva le informazioni \ microsecondi millisecondi – Jonathan
@jonathan: Grazie. – bavaza
Based sulla risposta di bavaza - ora inclusi i microsecondi:
def datetime2matlabdn(dt):
mdn = dt + timedelta(days = 366)
frac_seconds = (dt-datetime.datetime(dt.year,dt.month,dt.day,0,0,0)).seconds/(24.0 * 60.0 * 60.0)
frac_microseconds = dt.microsecond/(24.0 * 60.0 * 60.0 * 1000000.0)
return mdn.toordinal() + frac_seconds + frac_microseconds
- 1. fsolve su Python (conversione del codice MATLAB per codice Python)
- 2. python "import datetime" v.s. "Da datetime import datetime"
- 3. Parsing datetime in Python ..?
- 4. Python SqlAlchemy order_by DateTime?
- 5. Incorporamento Python in MATLAB
- 6. Matrix da Python a MATLAB
- 7. Comunicazione tra Python e Matlab
- 8. Datetime Python - Giorno lavorativo successivo
- 9. Traduci matlab in python/numpy
- 10. MATLAB ind2sub equivalente in Python
- 11. MATLAB ksdensity equivalente in Python
- 12. simulazione su MATLAB
- 13. Immagine deblurring su Matlab
- 14. Conversione stringa di datetime a datetime in NumPy (python)
- 15. Python & SCons & Matlab: Ingresso comando errato
- 16. Python non aspetta MATLAB per terminare
- 17. python - using json con OrderedDict e Datetime
- 18. Encoder JSON Python per supportare datetime?
- 19. Come impostare DateTime su null
- 20. Different timezone_types su oggetto DateTime
- 21. Quando scegliamo DateTime su Timestamp
- 22. Come impostare datetime su datetime-local tramite jQuery
- 23. Conversione del numero seriale excel DateTime su R DateTime
- 24. matlab "memoria" funzione su mac?
- 25. Numpy/Python prestazioni terribilmente vs. Matlab
- 26. Spogliarello i secondi in datetime python
- 27. Python -Togliere Tempo da Datetime String
- 28. Js Date object to python datetime
- 29. convertendo QdateTime in normale python dateTime?
- 30. Datetime anno corrente e mese python
In realtà si intende convertire un oggetto in una lingua in un oggetto in un altro? In tal caso, quale interfaccia stai usando (PyMat?) O intendi come stampi un oggetto datetime in un particolare formato? –
@DavidRobinson - no, intendo la rappresentazione testuale di 'datenum' che Matlab sa leggere. cose come '732399.65465' dove a sinistra è il giorno gregoriano dal 1/1/1 (o 1/1/0 ?!) e sulla destra è la frazione di un giorno – Jonathan