Freqz plotting warning when use latex as default interpreter

6 views (last 30 days)
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?

Accepted Answer

Star Strider
Star Strider on 25 Apr 2017
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.

More Answers (1)

Kelly Kearney
Kelly Kearney on 25 Apr 2017

The Latex interpreter assumes text is written in Latex text mode, and requires typical Latex markup ($ or $$) to switch the string (or parts of the string) to math mode. The TeX interpreter, on the other hand, supports a small subset of latex markup without needing the math-mode indicators.

Most plotting functions rely on the assumption that their axis labels will be interpreted with the tex interpreter. The valid latex version of freqz's xlabel captions would be 'Normalized Frequency ($\times\pi$ rad/sample)'. I don't know of any methods to automatically perform this conversion. I'd guess that using the LaTeX interpreter as the default is going to lead to a lot of these sorts of warnings, followed by manual adjustments.

Categories

Find more on Axes Appearance in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!