how to add date in the title ?

조회 수: 5 (최근 30일)
Lilya
Lilya 2018년 10월 22일
댓글: Lilya 2018년 10월 28일
Dear all,
I have a for loop to get a subplots of (2,5,i) % i = 1:10 that I want to add the title of the plots using specific period I have for each subplots ex: minimum date 14-4-2016, maximum date 19-4-2016 ...etc I want to get: 14-19 April 2016
Any help would be appreciated.
thanks a lot

채택된 답변

YT
YT 2018년 10월 22일
편집: YT 2018년 10월 22일
%get days only \/ output format
t = char(datetime({'14-4-2016','19-4-2016'},'InputFormat','dd-MM-yyyy','Format','d'));
day = strcat(t(1,:),'-',t(2,:));
%get month and year \/ output format
monthyear = char(datetime({'14-4-2016'},'InputFormat','dd-MM-yyyy','Format','MMMM y'));
final = [day ' ' monthyear];
% final = '14-19 April 2016'
More info on datetime can be found here
  댓글 수: 3
YT
YT 2018년 10월 23일
For example:
daysmonths = char(datetime(["30-4-2016","3-5-2016"],'InputFormat','dd-MM-yyyy','Format','d MMMM'));
dm = strip(string([daysmonths(1,:) ' - ' daysmonths(2,:)]),'right'); %made a string array from char and stripped excess spaces
final = strcat(dm," ",string(datetime(["3-5-2016"],'InputFormat','dd-MM-yyyy','Format','yyyy')))
%"14 April - 19 May 2016" as string array; if you want character array just use char(final)
Lilya
Lilya 2018년 10월 28일
you are the best, thank you so much!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Title에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by