Latex Interpreter Not Producing Expected Results

18 ビュー (過去 30 日間)
Matt Brown
Matt Brown 2022 年 9 月 29 日
コメント済み: Matt Brown 2022 年 10 月 3 日
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.

採用された回答

Cris LaPierre
Cris LaPierre 2022 年 9 月 29 日
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 件のコメント
Matt Brown
Matt Brown 2022 年 10 月 3 日
Awesome, thanks! I knew it was something I was missing on syntax. I appreciate the tip on \ as well.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by