Running into problems using the latex interpreter in strings
조회 수: 25 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
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';
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Title에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
