How do I turn date time into text

Hi, I need to use the text command to inset a date time into an image. Text only takes strings. I can't figure out how to make the current date time that I have computed into a text. Can you please help me?
specifically see below.
time_now=datetime(2017,7,23,7,48,04+dec_time); (assume dec_time is a counter that increments inside a loop.
fooim=figure;
imagesc(foo,clims); % all this is doing is making an image that I am interested in
colormap(gray)
text(200,200,time_now) % I want to put the date time I have calculated above into the image
thanks
Geoff

댓글 수: 1

Matthew McHarg
Matthew McHarg 2016년 8월 22일
I get the following error message when I try this.
Error using sprintf Function is not defined for 'datetime' inputs.

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

답변 (2개)

Walter Roberson
Walter Roberson 2016년 8월 22일

1 개 추천

char() the datetime object after having set its Format property.
Matthew McHarg
Matthew McHarg 2016년 8월 23일

0 개 추천

I am using 2015b, and it looks like the datestr command does what I need. I guess this is similar to the old num2str command. Thanks for all the help.

댓글 수: 1

Peter Perkins
Peter Perkins 2016년 8월 23일
datestr is not recommended, it's intended for backwards compatibility, and uses the older formatting "language". If you need a text representation of a datetime, recommended way is to use use char, as Walter suggests.

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

카테고리

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

태그

질문:

2016년 8월 22일

댓글:

2016년 8월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by