MATLAB: Putting transfer function expression in the title of a bode plot

bodeMATLABstrings

Hi Consider the following code snippet:
num=[1 2];
den=[1 7 49];
trans=tf(num,den);
tran=evalc(trans);
bode(trans)
Title=('Bode plot of:', tran)
I want to put the transfer function in the title in rational form as a function of s. I got it working but the title is cut off at the top of the figure window and maximising the window does not help. How can I adjust the vertical position of the title so that it will all be visible. Or is there a better way of converting the tf expression to a string variable that can be passed to the title. Many thanks for any help you can give me. Regards. Thomas

Best Answer

I couldn’t reproduce your results with your code (the evalc call threw an error in R2017a), so I used the Symbolic Math Toolbox to create the transfer function for the title.
The Code
num=[1 2];
den=[1 7 49];
trans=tf(num,den);
syms s
n = sym(num);
d = sym(den);
ns = poly2sym(n,s);
ds = poly2sym(d,s);
tfsym = ns/ds;
tftitle = latex(tfsym);
figure(1)
bode(trans)
title(sprintf('Bode plot of: $$ %s $$', tftitle), 'Interpreter','latex')
The Plot