print non-ASCII / symbolic characters in Matlab

本秂侑毒 提交于 2019-12-10 15:38:45

问题


I'd like to have a statement that did:

my_angle = 1*pi;
fprintf('My angle is %.3f pi.\n',my_angle/pi);

but that produced My angle is 1.000 pi, instead of the actual π character.

I'm thinking some sort of use of Unicode...

I found some related things:

  • Page on Unicode pi
  • Sort of related SO question
  • Perhaps a more relevant SO question

回答1:


I don't know how to do it with fprintf, but sprintf works – just leave off the semicolon:

sprintf('My angle is %.3f %c.\n',my_angle,char(960))

Or you can use disp:

disp(['My angle is ' num2str(my_angle,'%.3f') ' ' char(960) '.']);



回答2:


The answer depends on your OS. On Windows Matlab uses the windows-1252 character set which is pretty limited. I think char with values greater than 255 you get nothing/squares. On Linux you can use full UTF8 character sets and can use char with any value you want.



来源:https://stackoverflow.com/questions/19845628/print-non-ascii-symbolic-characters-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!