Latex Interpreter Not Producing Expected Results

29 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Cris LaPierre
Cris LaPierre il 29 Set 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')
  1 Commento
Matt Brown
Matt Brown il 3 Ott 2022
Awesome, thanks! I knew it was something I was missing on syntax. I appreciate the tip on \ as well.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by