How to print path in figure title? It's screwing up my TeX markup
4 次查看(过去 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 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!