need a time series

I need a time series with 1 sec interval.
the cell will contain 00:00:01
.
00:01:59
.
24:59:59
.
25:59:59
.
72:59:59
How to create this array?
thanks in advance
regards Moon

 Respuesta aceptada

José-Luis
José-Luis el 2 de Nov. de 2012
Editada: José-Luis el 2 de Nov. de 2012

3 votos

totHours = 72;
totMin = 12;
totSec = 21;
totVals = totHours*60*60+totMin*60+totSec;
hour_vec = cell2mat(arrayfun (@(x) repmat(x,60*60,1),(0:totHours)','uniformoutput',false));
min_vec = repmat(cell2mat(arrayfun(@(x) repmat(x,60,1),(0:59)','uniformoutput',false)),totHours+1,1);
sec_vec = repmat((0:59)',(totHours+1)*60,1);
your_string = reshape(sprintf('%02u:%02u:%02u',[hour_vec(1:totVals) min_vec(1:totVals) sec_vec(1:totVals)]'),8,[])';

6 comentarios

Andrei Bobrov
Andrei Bobrov el 3 de Nov. de 2012
+1
Moon Datta
Moon Datta el 5 de Nov. de 2012
Editada: Moon Datta el 5 de Nov. de 2012
If I want to change the interval then what is the correction needed here? I need the 64 second interval thanks in advance
José-Luis
José-Luis el 5 de Nov. de 2012
Editada: José-Luis el 5 de Nov. de 2012
Borrowing from Andrei. Every two seconds:
[z,y,x] = ndgrid(0:2:59,0:59,0:2);
p=reshape(sprintf('%02u:%02u:%02u',[x(:),y(:),z(:)]'),8,[])';
Note that 60 has to be divisible by the interval length (2 seconds in the example) in order to produce even intervals. If you need intervals that are not divisors of 60, then the logic you need to implement is a bit more complex, but you could always go the datenum() way.
Also, I have looked at your other questions in this forum. Please accept the answers if they have helped you. That is the only "payment" contributors to this forum get.
Moon Datta
Moon Datta el 6 de Nov. de 2012
Sir, It is working fine for second interval and minute interval. But I need the interval 64 second i.e.,1 minute 4 second. I am not understanding how to create this interval.
help please and thanks in advance
José-Luis
José-Luis el 6 de Nov. de 2012
Editada: José-Luis el 6 de Nov. de 2012
An alternative is:
numHH = 72;
numMM = 12;
numSS = 36;
totSec = 72*60*60 + 12*60 + 36;
secVals = 0:64:totSec; %your interval in seconds here
SSVec = mod(secVals,60);
MMVec = floor(mod(secVals,3600)/60);
HHVec = floor(secVals/3600);
your_string = reshape(sprintf('%02u:%02u:%02u',[HHVec; MMVec; SSVec]),8,[])';
I think this deserves another + vote. While I like to help, this is starting to feel like work. In the future, try asking a new question instead of repeatedly modifying your initial question.
Moon Datta
Moon Datta el 6 de Nov. de 2012
Thanks a lot Sir

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Operators and Elementary Operations en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by