Latex Interpreter Not Producing Expected Results

26 visualizaciones (últimos 30 días)
Matt Brown
Matt Brown el 29 de Sept. de 2022
Comentada: Matt Brown el 3 de Oct. de 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.

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 29 de Sept. de 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 comentario
Matt Brown
Matt Brown el 3 de Oct. de 2022
Awesome, thanks! I knew it was something I was missing on syntax. I appreciate the tip on \ as well.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by