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

11 views (last 30 days)
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 Comments
Ajinkya
Ajinkya on 25 Oct 2024
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 on 25 Oct 2024
@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...

Sign in to comment.

Accepted Answer

dpb
dpb on 24 Oct 2024
Moved: dpb on 25 Oct 2024
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?

More Answers (1)

Walter Roberson
Walter Roberson on 24 Oct 2024
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 Comment
dpb
dpb on 24 Oct 2024
Edited: dpb on 24 Oct 2024
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...

Sign in to comment.

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!