How to prevent unwanted line breaks when using sgtitle function in figure?
13 views (last 30 days)
Show older comments
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1494202/image.png)
0 Comments
Accepted Answer
Walter Roberson
on 26 Sep 2023
pt_blk is a cell array so pt_blk(si) is a cell array.
['Pt: ', {'429-040 vs 041'}, ', Contact:']
Alternately, pt_blk might be a string() array.
3 Comments
Walter Roberson
on 27 Sep 2023
Observe:
['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.
More Answers (0)
See Also
Categories
Find more on Numeric Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!