title('str​ing1_strin​g2'): Stop automatic subscripts?

조회 수: 68 (최근 30일)
Andrew Reibold
Andrew Reibold 2014년 10월 7일
편집: Andrew Reibold 2014년 10월 8일
I have a code that goes through many files and creates many plots that I distribute to different users. The plots are automatically titled (thank the heavens) to be whatever the file name is using the simple title() command.
Almost all of the files have an underscore in there somewhere, but it is never consistent.
'file_23', 'data_is_here', 'test_v13'
While it is not critical, its quite annoying that the title() command automatically wants to automatically assume that it should not print the underscore, but instead print the next letter as a tiny subscript.
Is there a way to disable this automatic feature? I want to print the underscore rather than make a subscript, however it is not practical for me to try to replace all the underscores with '\_'.
Just wondering if its something easy to disable.

채택된 답변

Image Analyst
Image Analyst 2014년 10월 8일
You have to set the interpreter to 'none' . Not sure the others knew of this or remembered it. But let's say that your file name has an under line in it and you want to see the underline. Simply do
title(filename, 'Interpreter', 'none');
Now the character after the underline will not be a subscript. It is documented in the title() documentation though it may not be so obvious.
  댓글 수: 1
Andrew Reibold
Andrew Reibold 2014년 10월 8일
편집: Andrew Reibold 2014년 10월 8일
Perfect. This is exactly the kind of solution I was looking for, thank you.
Thanks for the other answers too, upvotes for all, they might help someone else out. Its just that the code I inherited is just an absolute catastrophe when it comes to formatting and practice. It would take me a few pages of text to describe to you why the solutions suggested aren't/won't work as is. I'm sure we could have eventually figured something out with a few pages of more detail, but Image Analysts solutions works perfectly for my scenario, its easy, and I'm slightly embarrassed I didn't already know about it. I'm sure I set the Interpreter before, maybe as recent as a year ago, and I just totally forgot about it and couldn't find it again.

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

추가 답변 (2개)

Star Strider
Star Strider 2014년 10월 8일
‘it is not practical for me to try to replace all the underscores with '\'.’_
It can be. Use strrep:
ttls = {'file_23', 'data_is_here', 'test_v13'};
ttlsr = strrep(ttls, '_', '\_');
produces:
ttlsr =
'file\_23' 'data\_is\_here' 'test\_v13'

Azzi Abdelmalek
Azzi Abdelmalek 2014년 10월 7일
편집: Azzi Abdelmalek 2014년 10월 7일
Use
title('file\_23')

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by