How to include Markers in a string for title of a plot

조회 수: 64 (최근 30일)
Ajinkya
Ajinkya 2024년 10월 24일 11:57
댓글: dpb 2024년 10월 25일 12:27
I tried using the following command:
ttl = sprintf(' R1 = %0.2f and \x22D2 %s = %0.2f (in Consistent Units)', var(1), str(1),var(2) );
Then, I use ttl as title(ttl). However, MATLAB does not recognize the UNICODE character and prints simply a blank square. However, If I separately use sprintf('\x22D2') in command window, I can see the correct unicode character. Why does this happen and how to resolve it?
  댓글 수: 3
Ajinkya
Ajinkya 2024년 10월 25일 7:44
An update to the edit! It was the issue with font. "Arial" could not render the symbol. I changed it to Helvetica and it is working. Thank you for the help.
@dpb, I want to mark your answer as accepted but cannot do it since it is a comment (I think). Can you please post it as an answer so that I can do the needful?
dpb
dpb 2024년 10월 25일 12:27
@Ajinkya, ok thanks for letting us know it was, indeed a fonts issue. I thought it would be, but wasn't quite certain enough when initially posted to say a conjecture was an Answer... :)
So, I did move it over per request...

댓글을 달려면 로그인하십시오.

채택된 답변

dpb
dpb 2024년 10월 24일 13:20
이동: dpb 2024년 10월 25일 12:25
var=[pi exp(1)];
str='Fred';
ttl = sprintf(' R1 = %0.2f and \x22D2 %s = %0.2f (in Consistent Units)', var(1), str(1),var(2) );
title(ttl)
ttl
ttl = ' R1 = 3.14 and ⋒ F = 2.72 (in Consistent Units)'
seems to do the same thing here and also on the local machine. I expect it has to do with whether there is an installed font that has the expected glyph set; I think the square box is a fallback when not available...
What does
hAx=gca;
hTxt=hAx.Title;
hTxt.FontName
ans = 'Helvetica'
return on your system?

추가 답변 (1개)

Walter Roberson
Walter Roberson 2024년 10월 24일 12:59
Possibly you have set the default Interpreter on titles to 'latex'
var = rand(2,1);
str = "Hi there!";
ttl = sprintf(' R1 = %0.2f and \x22D2 %s = %0.2f (in Consistent Units)', var(1), str(1),var(2) );
title(ttl, 'Interpreter', 'none')
  댓글 수: 1
dpb
dpb 2024년 10월 24일 13:39
편집: dpb 2024년 10월 24일 19:42
var = rand(2,1);
str = 'Hi there!';
ttl = sprintf(' R1 = %0.2f and \x22D2 %s = %0.2f (in Consistent Units)', var(1), str(1),var(2) );
subplot(3,1,1)
hT=title(ttl, 'Interpreter', 'none');
hT.Interpreter
ans = 'none'
subplot(3,1,2)
hT=title(ttl, 'Interpreter', 'tex');
hT.Interpreter
ans = 'tex'
subplot(3,1,3)
hT=title(ttl, 'Interpreter', 'latex');
Warning: Error in state of SceneNode.
String scalar or character vector must have valid interpreter syntax:
R1 = 0.32 and ⋒ H = 0.26 (in Consistent Units)
hT.Interpreter
ans = 'latex'
They all seem to display the same although the 'LaTeX' does produce a warning message. OP didn't mention getting any errors or warnings, just that the symbol wasn't rendered. Of course, that doesn't prove didn't, agreed...
I presume that when LaTeX errors internally it reverts to another choice but doesn't change the state of the 'Renderer' property that could cause other valid LaTeX sequences to fail is why it ends up displaying the same text as either 'none' or 'tex'
A pretty quick and far from thorough search makes it appear there is no universal way to display unicode characters in LaTeX and given that one cannot add packages into the MATLAB embedded version, it would appear that that choice is not one to pick, anyway.
As above, I think it will be the font OP is using doesn't support the particular glyph...but we don't know what is using...

댓글을 달려면 로그인하십시오.

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by