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

64 visualizaciones (últimos 30 días)
Ajinkya
Ajinkya el 24 de Oct. de 2024 a las 11:57
Comentada: dpb el 25 de Oct. de 2024 a las 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 comentarios
Ajinkya
Ajinkya el 25 de Oct. de 2024 a las 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 el 25 de Oct. de 2024 a las 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...

Iniciar sesión para comentar.

Respuesta aceptada

dpb
dpb el 24 de Oct. de 2024 a las 13:20
Movida: dpb el 25 de Oct. de 2024 a las 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?

Más respuestas (1)

Walter Roberson
Walter Roberson el 24 de Oct. de 2024 a las 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 comentario
dpb
dpb el 24 de Oct. de 2024 a las 13:39
Editada: dpb el 24 de Oct. de 2024 a las 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...

Iniciar sesión para comentar.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by