change the first digits when ends with 5959
1 view (last 30 days)
Hey, I've got a doubt. I have a string of numbers that go from 0000 to 5959(First two are the minuts and the other two the seconds), when it reaches another time 0000 I wanted to add a unit that goes from 1 to 23(that indicates the hours). I have added this line of code:
T_Hour_1 = '00'+t1; % it gives us t1 with two 00 that indicates the hour
then I got this lines of code that changes the string of T_Hour_1 to dur.
DN1 = str2double(t1);
dur1 = minutes(floor(DN1/100)) + seconds(mod(DN1,100)); % separar en minutos y segundos
[~, M1, S1] = hms(dur1); % Dar tiempo en 2 variables, utilizar M1 para crear rangos
Before doing DN1 I would like to add the numbers from 0 to 23 in front of the others.
How could I do it?
Thank you for your help!!
Stephen23 on 21 Sep 2021
Edited: Stephen23 on 21 Sep 2021
Rather than messing around with strings you should probably just work with duration objects or numeric arrays.
S = ["000000";"000059";"000100";"000159";"005959";"000000";"005959";"000000";"005900"]
D = duration(strcat(extractBefore(S,3),':',extractBetween(S,3,4),':',extractAfter(S,4)))
D = D + hours(cumsum([0;diff(D)<0]))