MATLAB: Freqz plotting warning when use latex as default interpreter

freqzlatex

At the top of my file I have :
set(0, 'defaulttextinterpreter', 'latex');
set(0, 'defaultlegendinterpreter', 'latex');
set(groot, 'defaultAxesTickLabelInterpreter', 'latex');
set(groot, 'defaultLegendInterpreter', 'latex');
so all my plots output as LaTeX. However, when I plot with freqz I get the warning:
Warning: Error updating Text.
Character vector must have valid interpreter
syntax:
Normalized Frequency (\times\pi rad/sample)
Warning: Error updating Text.
Character vector must have valid interpreter
syntax:
Normalized Frequency (\times\pi rad/sample)
Is there a way to fix this so I don't get this output every time I run freqz?

Best Answer

Kelly is correct — you can’t do this automatically but it is possible. This uses R2014b and later ‘HG2’ syntax, so change to the get and set syntax if you are using an earlier version.
Example:
freqz([1 0 1],[1 0],2^12)
h211 = get(subplot(2,1,1)); % Necessary Handle

h212 = get(subplot(2,1,2)); % Necessary Handle
h211.XLabel.Interpreter = 'latex'; % Previously Set, So Omit This Line (Testing My Code)



h212.XLabel.Interpreter = 'latex'; % Previously Set, So Omit This Line (Testing My Code)
h211.YLabel.Interpreter = 'latex'; % Previously Set, So Omit This Line (Testing My Code)
h212.YLabel.Interpreter = 'latex'; % Previously Set, So Omit This Line (Testing My Code)
xlbl = h211.XLabel.String; % Get Existing String


h211.XLabel.String = ['$' xlbl '$']; % Reformat To LaTeX-Compatible Code



h212.XLabel.String = ['$' xlbl '$']; % Reformat To LaTeX-Compatible Code
ylblm = h211.YLabel.String; % Get Existing String
h211.YLabel.String = ['$' ylblm '$']; % Reformat To LaTeX-Compatible Code
ylblp = h212.YLabel.String; % Get Existing String
h212.YLabel.String = ['$' ylblp '$']; % Reformat To LaTeX-Compatible Code
Fortunately, unlike bode and the Control System and related Toolbox functions, freqz is an ordinary subplot. (I set the interpreter to 'latex' here so I could test this, but since you already have, omit that line in your code.) Do the same for the phase plot (as subplot(2,1,2)), and for the 'YLabel' for each subplot.
You can do this for the tick labels as well, with extra lines of code for each.
If you want to do this automatically, set up your own function that accepts the normal freqz arguments, then passes them to freqz, incorporating in your function the necessary expressed or implied get and set commands to use the LaTeX interpreter.
Related Question