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

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