How to print path in figure title? It's screwing up my TeX markup

1 view (last 30 days)
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!

Accepted Answer

Star Strider
Star Strider on 29 Jul 2014
Edited: Star Strider on 29 Jul 2014
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.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!