How to convert from matlab time to reall time and date

I have
datestr(7.3684e+05)
ans =
'25-May-2017'
But I need the time and seconds aswell, How do I get this ?
whith this information - I am trying to combine this with [x y]=ginput, as I want to take the times off a graph.
I have tried using
datetick('x', 'dd/mm - HH:MM', 'keepticks', 'keeplimits'); and datetick('x')
Any advise would be appreciated as I am not following the help pages for this problem

 채택된 답변

Stephan
Stephan 2018년 11월 26일
편집: Stephan 2018년 11월 26일

0 개 추천

datestr(7.3684e+05,'dd-mmmm-yyyy HH:MM:SS')
ans =
'25-May-2017 00:00:00'
or with some content in it:
>> datestr(7.3684e+05+13.42,'dd-mmmm-yyyy HH:MM:SS')
ans =
'07-June-2017 10:04:48'
Best regards
Stephan

댓글 수: 4

Thank you for your reply - as it is rounded I get all my values as 7.3684e+05 with ginput - how would I get the points without rounding them as this is important in the time conversion. I am using [x y]=ginput. see exaple attached
Stephan
Stephan 2018년 11월 26일
편집: Stephan 2018년 11월 26일
Hi,
this seems to work:
% Some data to play with
t1 = datetime('2018-01-01 12:00:00');
t2 = datetime('2018-01-18 06:00:00');
t = t1:days:t2;
val = randi(10,1,numel(t));
%Show figure
fig = figure(1);
plot(t,val)
% Get 5 Points
[x,y] = ginput(5);
% Calculate the picked dates with time
date_x = x(:)+t1;
In my tests i got results which seem to be correct. For example:
date_x =
5×1 datetime array
04-Jan-2018 08:51:13
04-Jan-2018 20:18:13
07-Jan-2018 12:03:05
09-Jan-2018 23:28:01
11-Jan-2018 05:29:03
I am getting :
'15-Oct-4034 01:40:08'
'15-Oct-4034 13:40:38'
'15-Oct-4034 01:59:33'
'15-Oct-4034 13:47:54'
But they should be all 23rd/24th of may 2017
When I follow:
% t1 = datetime('23-May-2017 09:15:00');
%change format to :
t1 = datetime('2017-05-23 09:15:00');
% Get 5 Points
[x,y] = ginput(4);
% Calculate the picked dates with time
date_x = x(:)+t1;
time = datestr(x)
time =
4×20 char array
'23-May-2017 16:25:08'
'24-May-2017 04:25:38'
'23-May-2017 16:44:33'
'24-May-2017 04:32:54'
And it seemed to have worked, thank you for helping me get to here. much appreciated.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Peter Perkins
Peter Perkins 2018년 11월 27일

0 개 추천

Rebecca, your description is not clear enough to understand what you are trying to do, but unless you are using a fairly old version of MATLAB, you should try to stay away from the old datenum/datestr functions and use datetime instead.

카테고리

도움말 센터File Exchange에서 Time Series Objects에 대해 자세히 알아보기

태그

질문:

2018년 11월 26일

답변:

2018년 11월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by