Latex Interpreter Not Producing Expected Results

25 vues (au cours des 30 derniers jours)
Matt Brown
Matt Brown le 29 Sep 2022
Commenté : Matt Brown le 3 Oct 2022
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.

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by