print non-ASCII / symbolic characters in Matlab

2019-06-25 09:26发布

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:

2条回答
啃猪蹄的小仙女
2楼-- · 2019-06-25 09:52

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) '.']);
查看更多
一夜七次
3楼-- · 2019-06-25 09:53

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.

查看更多
登录 后发表回答