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!