Convert variable to a title - includes special charcters

조회 수: 26 (최근 30일)
MathKat
MathKat 2015년 2월 23일
편집: Guillaume 2015년 2월 23일
I am storing a file name as a variable to be retrieved. But, the name of the file contains underscores. When I use the variable name as the title of my plot each letter that follows an underscore becomes subscripted. What I would like is for the underscores to remain underscores. Example: FileName=SD_Padres_are_great;
Then I plot a chart & I use this as the title: title(FileName);
In the above example the output title would print with the underscores missing and the P a & g subscripted.
Does anyone know how to keep the title in the exact format of the FileName? BTW-I do not have control of the file names to change them as they are created by another program.

채택된 답변

Jacob Matthews
Jacob Matthews 2015년 2월 23일
You could use the command "strrep" to replace the underscores with spaces:
strrep(FileName,'_',' ')
or if you want to keep the filename exact with the underscores, insert a backslash:
strrep(FileName,'_','\_')
which will print the underscore as an underscore instead of treating it as a indicator for subscripting.
  댓글 수: 1
Guillaume
Guillaume 2015년 2월 23일
Or you could just tell title to not interpret the string as Tex... (set the 'Interpreter' to 'none').

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

추가 답변 (1개)

Guillaume
Guillaume 2015년 2월 23일
title(string_with_underscores, 'Interpreter', 'none')
will solve it. It's in the doc!
  댓글 수: 4
MathKat
MathKat 2015년 2월 23일
편집: MathKat 2015년 2월 23일
I'm sure it is user error :) BTW - could it be because I am running on 2012b?
Thx again.
Guillaume
Guillaume 2015년 2월 23일
편집: Guillaume 2015년 2월 23일
Nope, this has been the documented way since at least 2010.
Strike that, since at least 2003

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

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by