필터 지우기
필터 지우기

How to append text and numbers into a title

조회 수: 36 (최근 30일)
Paul Barrette
Paul Barrette 2023년 11월 2일
댓글: Paul Barrette 2023년 11월 3일
I am trying to get the title to a plot on two lines, with the first line being a string, and the second one being a combination of a string, day number and month name. Following is one of a number of unsuccessful attemps.
start_month=12;
start_day=1;
mth = month(datetime(1, start_month_ISI, 1), 'Name'); % To get the name of the month
title({'C. Beauharnois';'No. of days to first ISI=1 since',+start_day+'mth'});
The title should show up as follows:
1st line: C. Beauharnois
2nd line: No. of days to first ISI=1 since December 1
Tx!

채택된 답변

Walter Roberson
Walter Roberson 2023년 11월 2일
Or use
start_month = 12;
start_day = 1;
mth = month(datetime(1, start_month, 1), 'Name'); % To get the name of the month
title(["C. Beauharnois"; "No. of days to first ISI=1 since " + start_day + " " + mth]);
  댓글 수: 1
Paul Barrette
Paul Barrette 2023년 11월 3일
The solution by @Matt J and by @Voss below are also good, but this one is simpler. It also includes an interesting option (subtitle) as an alternative approach.

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

추가 답변 (3개)

Matt J
Matt J 2023년 11월 2일
start_month=12;
start_day=1;
mth = month(datetime(1, start_month, 1), 'Name'); % To get the name of the month
title({'C. Beauharnois';['No. of days to first ISI=1 since ',mth{1} ' ' num2str(start_day)]});

Voss
Voss 2023년 11월 2일
start_month_ISI=12;
start_day=1;
mth = month(datetime(1, start_month_ISI, 1), 'Name'); % To get the name of the month
title({'C. Beauharnois';sprintf('No. of days to first ISI=1 since %s %d',mth{1},start_day)});

Les Beckham
Les Beckham 2023년 11월 2일
편집: Les Beckham 2023년 11월 2일
You were so close, but you can't use + to concatenate character vectors, use strings instead.
I changed the single quotes to double quotes, removed an extraneous comma and changed the reference to start_month_ISI to start_month (and added some spaces).
start_month=12;
start_day=1;
mth = month(datetime(1, start_month, 1), 'Name'); % To get the name of the month
title({"C. Beauharnois";"No. of days to first ISI=1 since " + start_day + " mth"});
  댓글 수: 1
Paul Barrette
Paul Barrette 2023년 11월 3일
Thanks, Les! But that is not quite what I was looking for.

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

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by