What happens when I call the ␇ character in MATLAB

邮差的信 提交于 2019-12-02 10:44:37

问题


Whilst attempting to answer the Play a sound any sound question, I ran into the character.

However, when trying to call this in MATLAB, I noticed something strange: Nothing happened.

Using R2012b, I copied it from the browser into MATLAB.

Here are some observations:

  1. When pasting the character, a red colored square is displayed
  2. When hitting enter, no error was given.
  3. Adding zero to it ␇ +0 also does nothing.
  4. Using it in a string seems possible, but gives a strange result: '␇'+0 = 26
  5. Calling it in a function does something strange, try mean(␇) and your command never seems to end (except with control+c)

To conclude, here is my main question:

What happens when I run in Matlab, and why does MATLAB treat this apparently invalid input in such a strange way?


回答1:


The character you entered is just another Unicode character outside the range that the MATLAB command prompt (and possibly even the editor) knows how to display. Just because it represents the "symbol for bel" doesn't mean it has any special significance or would play a sound when entered (no more than other musical symbols like: or 🎻)

Of course you can always have it saved in a regular string and display it in a GUI window:

% The default on Windows is 'windows-1252'
feature('DefaultCharacterSet','UTF-8')

c = char(9223);
uicontrol('style','text', 'units','normalized', 'position',[0 0 1 1], ...
    'string',['char = ' c], 'FontName','Arial Unicode MS', 'FontSize',72)

or even get its encoding in say UTF-8:

>> cellstr(dec2hex(unicode2native(c,'UTF-8')))
ans = 
    'E2'
    '90'
    '87'


来源:https://stackoverflow.com/questions/21097072/what-happens-when-i-call-the-character-in-matlab

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