Change the title of a Bode Plot

Hi all,
I've been working with the Bode Plot options in MATLAB, speciffically bodeplot so as to customise it a bit more.
I've manged to figure out how to change axis limts and so on, but I canot figure out how to change the title of the plot to have it reflect the following title for example; "Bode plot of "
I can get it to work for a plot using the plot command, but not for the bodeplot. I can index into the structure, but can't get the latex to work in there, it just comes back with text, and not the desired title. I've only just started working with LaTex within MATLAB, so I guess my issue is there.
Any help appreciated.
Thanks
Gerard
clear;
clc;
Gsys = tf(2,[0.25 1]);
h = bodeplot(Gsys);
t = '$\frac{8}{{{s}^{2}}+4s}$';
p = getoptions(h);
p.XLim = {[0.1 100]};
p.YLim(1) = {[-60 30]};
p.YLim(2) = {[-180 90]};
p.Title.String = {['t','interpreter','latex']};
setoptions(h,p);
grid
axes_handles = findall(gcf, 'type', 'axes');
leg = legend(axes_handles(3),'$\frac{8}{s(s+4)}$','interpreter','latex');
set(leg,'FontSize',17);
set(leg,'Location','southwest');
hold on

 Accepted Answer

p.Title.String = t;
p.Title.Interpreter = 'latex';
and you'll probably want
p.Title.FontSize = 20;

4 Comments

Hi Adam,
Thank you of the very quick reply, and for getting it to work.
I am seeing an error
Warning: Error updating Text.
String scalar or character vector must have valid interpreter syntax:
Bode plot of $\frac{8}{{{s}^{2}}+4s}$
Which seems to be in the setoptions(h,p) command. Any ideas why this would be?
Thank you in advance
Gerard
Output from Livescript below
Warning: Error updating Text.
String scalar or character vector must have valid interpreter syntax:
$\frac{8}{{{s}^{2}}+4s}$
I see the same warning in MATLAB R2021a but not in R2021b or later so that must have been addressed.
If you want to suppress the warning in R2021a, execute this line prior to using setoptions and then you can turn it back on afterwards in case the warning is useful in other functions.
warning('off','MATLAB:handle_graphics:exceptions:SceneNode')
Gerard Nagle
Gerard Nagle on 16 Mar 2022
Edited: Gerard Nagle on 16 Mar 2022
Hi Adam,
Yep, I updated to 2022a, and the warnings have gone away, so it seems to have been addressed in these later versions.
Also an issue with opening of the live script figure in a figure window has also been taken care of in the newer releases.
Adam, thank you for your help and expertise, very much appreciate. Take care and all the best
Gerard
Terrific! Happy to help.

Sign in to comment.

More Answers (0)

Products

Release

R2021a

Asked:

on 15 Mar 2022

Commented:

on 16 Mar 2022

Community Treasure Hunt

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

Start Hunting!