필터 지우기
필터 지우기

How to prevent unwanted line breaks when using sgtitle function in figure?

조회 수: 5 (최근 30일)
Hello Dears,
I created a general title which is supposed to be 1 line for a figure using the sgtitle function.
sgtitle([ 'Pt: ' pt_blk(si) ', Contact: ' num2str(cont2use(ti)) ', Target: ' hem{ti} ' ' target{ti} ' ' abbrev{ti}])
for some reason, it created multiple unwanted line breaks. Can anyone help please?

채택된 답변

Walter Roberson
Walter Roberson 2023년 9월 26일
pt_blk is a cell array so pt_blk(si) is a cell array.
['Pt: ', {'429-040 vs 041'}, ', Contact:']
ans = 1×3 cell array
{'Pt: '} {'429-040 vs 041'} {', Contact:'}
Alternately, pt_blk might be a string() array.
  댓글 수: 3
Walter Roberson
Walter Roberson 2023년 9월 27일
Observe:
['ET' "call" 'home']
ans = 1×3 string array
"ET" "call" "home"
When you concatenate a character vector and a string array, the character vectors are converted into string arrays.
You have several choices:
  • You can strjoin the string array
  • You can use + to join the parts, such as "Pt: " + pt_blk(si) + ", Contact: ' + cont2use(ti) + ", Target: ' + hem(ti) + ' ' + target(ti) + ' ' + abbrev(ti)
  • You can use {} indexing , pt_blk{si} instead of pt_blk(si)
It looks to me as if you are likely already using {} indexing as your solution everywhere other than that one place in the code.
ET
ET 2023년 9월 27일
Many thanks, Mr. Roberson. The strjoin function works
sgtitle(strjoin([ 'Pt:' pt_blk(si) ', Contact:' num2str(cont2use(ti)) ', Target:' hem{ti} target{ti} '(' abbrev{ti} ')'] ))

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by