How can I calculate the difference in time (seconds) with datetime?
Afficher commentaires plus anciens
I have to read a csv file. A column of this file has the next format:
2014/01/16 13:12:12.
Thanks for the help of Mischa Kim I have achieved to read in this format, so this not a problem.
So that my goal is to represent in X axis the time in seconds and Y axis the RSSI related to each second because as you can said me the problem if I represented the TIME_STAMP in the format 13:13:12 there're too many labels If I print all of them.
The First value of TIME_STAMP is 13:12:12 that corresponds to second 1. The Second Value of TIME_STAMP is 13:12:13 that corresponds to second 2. Until the last value...
If you don't understand my question tell me and I'll try to explain better!
Dou you Know a function or a way to calculate the TIME_STAMP in seconds with the aim to represent in x axis the time in seconds with each value.
I attach the csv file.
I would be grateful If you Know how can I do this! Thanks Mischa for your time! Greetings.
Réponse acceptée
Plus de réponses (2)
Jos (10584)
le 17 Fév 2014
You can also use the dedicated function ETIME (with DATEVEC)
date1 = '2014/01/16 13:12:12'
date2 = '2014/01/16 13:12:13' % one second later
etime(datevec(date2),datevec(date1))
If you have a list of date/times
DT = {'2014/01/16 13:12:13' '2014/01/16 13:12:15' '2014/01/16 13:13:13' '2014/01/17 13:12:13' }
reftime = DT{1} ;
etime(datevec(DT), repmat(datevec(reftime),numel(DT),1))
5 commentaires
Diego
le 17 Fév 2014
Jos (10584)
le 17 Fév 2014
You can convert a N-by-M char array to a N-by-1 cell array of strings of length M, using CELLSTR
A = ['abcd' ; '1234' ; 'xxxx'] % a 3-by-4 char array
B = cellstr(A) % a 3-by-1 cell array of strings
% B{k} equals A(k,:)
Diego
le 17 Fév 2014
João Campos
le 13 Avr 2021
It worked for me, but I am losing my miliseconds information :(, does anybody knows how to fix that?
In the years since the original answer for this question we introduced the datetime array that you should use instead of converting to datenum values.
dt = datetime('now')
dt2 = dt + seconds(1.2345)
s = seconds(dt2-dt)
sihem chaib
le 14 Fév 2014
1 vote
please how to declare increment beam length in matlab progamme
1 commentaire
Diego
le 17 Fév 2014
Catégories
En savoir plus sur Dates and Time dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!