Running into problems using the latex interpreter in strings

I have attached a code snippet that I'm trying to execute (Matlab Ver. 2024b):
I get warnings as follows:
Warning: Error in state of SceneNode.
String scalar or character vector must have valid interpreter syntax:
Inband Radiance, $\\left[\\frac{W}{\\mathrm{m}^2\\,\\mathrm{sr}}\\right]$
> In defaulterrorcallback (line 12)
In matlab.graphics.illustration/ColorBar/get.Label
Warning: Error in state of SceneNode.
String scalar or character vector must have valid interpreter syntax:
Event # 0089, Filter Wheel #1: Spectral Range = 1.97-5.39 $\\mu$m
The colorbar label looks ok to me, but the interpreter in the figure title is not interpreted at all,and just shows up as $\mu$ in the title (see the attached. .png file). Could someone please let me know what I am doing incorrectly?

 採用された回答

Matt J
Matt J 2025 年 7 月 28 日
編集済み: Matt J 2025 年 7 月 28 日
There are two issues, mainly.
(1) You should set the Interpreter first (before the String), to avoid the warnings
(2) Because it's LaTeX, your pound signs need slashes: \#
XCoors = 1:320;
YCoors = 1:256;
A = rand(numel(XCoors),numel(YCoors));
spRangeSel = ' 1.97-5.39';
channelNum = 1;
eventNum = 1;
fig = figure;
figWidth = 0.65;
figHeight = figWidth*XCoors(end)/YCoors(end);
set(gcf,'units','normalized','Position',[(1-figWidth)/2 (1-figHeight)/2 figWidth figHeight],'color','white');
h=imagesc(XCoors,YCoors,A); shading interp; colormap hot; axis equal
a = colorbar;
a.Label.Interpreter = 'latex';
a.Label.String = 'Inband Radiance, $\left[\frac{W}{\mathrm{m}^2\,\mathrm{sr}}\right]$';
ax1 = gca;
ax1.FontSize=20;
xlabel(ax1,'X [mm]','Fontsize',24,'interpreter','latex');
ylabel(ax1,'Y [mm]','Fontsize',24,'interpreter','latex');
ax1.Title.Interpreter = 'latex';
ax1.Title.String = ['Event \# ',num2str(eventNum,'%4.4d'),', Filter Wheel \#',int2str(channelNum),': Spectral Range =',spRangeSel,' $\mu$m'];
ax1.Title.FontName = 'Times';

1 件のコメント

MBP
MBP 2025 年 7 月 29 日
Thank you! I forgot I needed to escape the '#' symbols too!

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

その他の回答 (0 件)

製品

リリース

R2024b

質問済み:

MBP
2025 年 7 月 28 日

コメント済み:

MBP
2025 年 7 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by