How to display the celcius sumbol (°C) using fprint??
307 ビュー (過去 30 日間)
古いコメントを表示
I am creating an output file using fprint and want to display the unit of temperature in Celcius. Anyone knows how to do this?
0 件のコメント
採用された回答
Stephen23
2015 年 6 月 23 日
編集済み: Stephen23
2019 年 12 月 4 日
Here are four methods:
fid = fopen('temp.txt','wt');
fprintf(fid,'symbol one: °C\n');
fprintf(fid,'symbol two: %cC\n',176);
fprintf(fid,'symbol three: %cC\n',char(176));
fprintf(fid,'symbol four: \260C\n');
fclose(fid);
And the generated file:
symbol one: °C
symbol two: °C
symbol three: °C
symbol four: °C
7 件のコメント
Michael
2019 年 12 月 3 日
Out of curiosity, where do the codes in Walter's helpful comment come from? I knew that the degree symbol could be produced by Alt + 0176 so it didn't surprise me that passing 176 to a %c in fprintf gave me the right symbol.
>> fprintf('%c\n',176)
°
However, for my particular application, I can avoid needing to add a cumbersome workaround if I could put the symbol right in the format string. But these didn't give me what I expected:
>> fprintf('\176\n')
~
>> fprintf('\x176\n')
Ŷ
>> fprintf('\0176\n')
~
>> fprintf('\x0176\n')
Ŷ
Obviously using the code Walter suggested worked, but how did you know the degree symbol was \260?
>> fprintf('\260\n')
°
Stephen23
2019 年 12 月 4 日
編集済み: Stephen23
2019 年 12 月 4 日
"but how did you know the degree symbol was \260?"
- using hexadecimal '\xN'
- using octal '\N'
The value 176 is decimal, so it cannot be used directly with either of those syntaxes, but if you convert it to the correct base it it will work exactly as documented (although watch out for the catch that Walter Roberson showed when using hexadecimal with a trailing 'C' character).
その他の回答 (1 件)
Ingrid
2015 年 6 月 23 日
first search the previous answers and you will find what you are looking for: http://www.mathworks.com/matlabcentral/answers/32376-degree-symbol
I prefer to use:
^{\circ}
2 件のコメント
Walter Roberson
2019 年 12 月 4 日
\circ is also a work-around. I am told that publications do not like \circ as it is not considered a correct degree symbol. I seem to recall it is not raised at the correct height for a proper degree symbol.
参考
カテゴリ
Help Center および File Exchange で Numbers and Precision についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!