Troubles with Matlab&Simulink input time format

1 visualización (últimos 30 días)
Bozhidar Stoyanov
Bozhidar Stoyanov el 24 de Feb. de 2017
Respondida: Bozhidar Stoyanov el 25 de Feb. de 2017
Hi I have a time in format 123456.78 where 12 is hour, 34 minutes , 56 secounds and i need to get (12:34:56.78). I have tried to add ':' after every pair, but it didn't work. When i use datestr funcion, it give me back bad answer because datestr is working with day that means 1.5 = 12:00 can you help me please.

Respuesta aceptada

Bozhidar Stoyanov
Bozhidar Stoyanov el 25 de Feb. de 2017
Problem Solved :) M is matrix [x,1] where is the time in format 123456.78 (12:34:56.78) in every cell.
Date(1,12)=char(0);
pom=(M(1,1)*100);
if pom==0;
x=datestr(pom,'HH:MM:SS.FFF');
else
pom=num2str(pom);
x=cellstr(reshape(pom,2,[])');
x=transpose(x);
x=strjoin(x,{':',':','.'});
x=datestr(x,'HH:MM:SS.FFF');
end
Date(1,:)=x(1,:);

Más respuestas (1)

Easwar Kumar Yarrabikki
Easwar Kumar Yarrabikki el 24 de Feb. de 2017
Editada: Easwar Kumar Yarrabikki el 24 de Feb. de 2017
Hello This is how I deal with date and time in MATLAB,
Hope it will help you. it will give you date and time of that particular run.
you can change "_" to any symbol you want use, Either ":" or Some thing else .
format = 'yyyy_mm_dd_HH_MM_SS';
date_time = datestr(now, format)
  1 comentario
Bozhidar Stoyanov
Bozhidar Stoyanov el 24 de Feb. de 2017
Editada: Bozhidar Stoyanov el 24 de Feb. de 2017
datestr is working with days like i say. I think its possible to find a constant with which I would multiply the fractional number and then use this function
>> formatOut = 'HH:MM:SS:FFF';
>> date_now = datestr(123758.16, formatOut)
date_now =
03:50:24:000
>> but the time is (123758.16) 12:37:58.16

Iniciar sesión para comentar.

Categorías

Más información sobre Dates and Time en Help Center 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