How do I display the degree symbol on a figure using the SPRINTF function?
36 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I would like to use the degree symbol in one of the text objects that I am placing on my figure. This object is represented by the \circ escape sequence. I can use it well in the following manner:
text(1,1, '45\circ');
However, I have additional variables that I need to insert in my string expression for which I need to use the SPRINTF function as follows:
text(1,1, sprintf('%d\circ', x))
% where x = 45
The SPRINTF function however does not accept the \circ operator and gives a warning. The XLABEL, YLABEL, TEXT and other functions all accept this escape sequence.
Respuesta aceptada
MathWorks Support Team
el 13 de Sept. de 2012
The SPRINTF function in MATLAB does not support the \circ escape sequence for the degree symbol as this is not defined by the C standard with which this function has been modeled.
To work around this issue, you can perform one of the following:
1. Use the ASCII value of the degree symbol (176) in conjunction with the CHAR function within SPRINTF as follows:
s = sprintf('45%c', char(176));
Note that different fonts interpret ASCII values differently and you should verify this value before using it.
2. Use NUM2STR to create the desired string and then pass into the TEXT command.
x= 45;
text(1,1, [num2str(x) '\circ'])
0 comentarios
Más respuestas (0)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!