Latex Interpreter Not Producing Expected Results
26 views (last 30 days)
Show older comments
Greetings,
I am working on an app which has a plot for which the axis labels need to change depending on several user selections including a change of unit systems. To accomplish this I was simply appending a unit string onto a label and it seems to have worked fine for my y-axis. However, the x-axis seems to not play by the same rules. I assume that I have some kind of syntax error, but I have no idea what or where and would appreciate a second set of eyes. Here is an excerpt of the code which produces my axis labels:
% define unit appendage
if strcmp(app.UnitSystemDropDown.Value,'US - US Customary Units')==1
y2unit='[inWC]';
x2unit='[g/ft^{2}]';
else
y2unit='[mbar]';
x2unit='[g/m^{2}]';
end
% define y axis label
if strcmp(app.YAxisTypePressureDropDropDown.Value,'Pressure Drop')==1
y2label=['Pressure Drop, $\Delta p$ ',y2unit];
else
y2label=['Pressure Drop Increase, $\Delta p_{rise}$ ',y2unit];
end
% define x axis label
if strcmp(app.XAxisTypeDustDropDown.Value,'Total Encounter')==1
x2label='Total Dust Encounter, $m_{tot}$ [g]';
elseif strcmp(app.XAxisTypeDustDropDown.Value,'Filter Capacity')==1
x2label='Filter Capacity, $m_{cap}$ [g]';
elseif strcmp(app.XAxisTypeDustDropDown.Value,'Normalized Encounter')==1
x2label=['Normalized Encounter, $\bar m_{tot}$ ',x2unit];
else % normalized capacity
x2label=['Normalized Capacity, $\bar m_{cap}$ ',x2unit];
end
% set labels
app.DLoadPlot.XLabel.String=x2label;
app.DLoadPlot.YLabel.String=y2label;
app.DLoadPlot.XLabel.Interpreter='latex';
app.DLoadPlot.YLabel.Interpreter='latex';
This produces the following set of axis labels in my window. As you can see, the normalized encounter and normalized capacity strings aren't doing what I hoped.
0 Comments
Accepted Answer
Cris LaPierre
on 29 Sep 2022
The problem is that x2unit contains symbols that have meaning in LaTeX markup in MATLAB. Consider including your unit inside the LaTeX '$'. BTW, the '\ ' adds a space between mbar and unit.
x2unit='[g/ft^2]';
x2label=['Normalized Encounter, $\bar m_{tot} \ ',x2unit,'$'];
xlabel(x2label,'Interpreter','latex')
More Answers (0)
See Also
Categories
Find more on Environment and Settings 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!