How to print path in figure title? It's screwing up my TeX markup
조회 수: 5 (최근 30일)
이전 댓글 표시
What I want to achieve is a 3-line title over a plot which looks like this:
General Title
File name
Path where file lives
(The file name and path name refers to the file I used to do the calculations.) The different lines would have different properties -- for instance the General Title would have a larger font size than the two lines below it. Everything works as intended except for the path -- that screws up everything. If I exclude the path name, I can generate a nice 2-line title like this:
title({'\fontsize{16}Correlation Over Time';...
['\fontsize{9}\itFile\rm:',FileName]})
Note how I use TeX commands. It works as intended. As soon as I try to include the pathname, it all breaks. This is my attempt, just extending the logic of the above:
title({'\fontsize{16}Correlation Over Time';...
['\fontsize{9}\itFile\rm:',FileName];...
['\fontsize{9}\itPath\rm:',PathName]})
The TeX markup syntax and Windows path specification both use the '\' character, so matlab interprets the '\' characters in the PathName string as TeX commands. As a result, the entire title command breaks down, and it just spits out all the characters inside the parentheses unformatted. Is there any way for me to get around this?
Thanks!
댓글 수: 0
채택된 답변
Star Strider
2014년 7월 29일
편집: Star Strider
2014년 7월 29일
You have to replace the single backslant ‘\’ in the path name with double backslants ‘\\’ to make that work with TeX. They will print as single backslants though, so it will look as it should. The easiest way to do that is with the strrep function:
path = 'C:\Documents\MATLAB\DragonFiles';
PathName = strrep(path, '\', '\\');
You don’t have to change anything else, and it only changes the string you pass to your title call, leaving the actual path string unchanged. It worked when I tried it on a figure I created to test it, so you should have no problems with PathName created here.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!