Question

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?

Was it helpful?

Solution

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)

bel_symbol

or even get its encoding in say UTF-8:

>> cellstr(dec2hex(unicode2native(c,'UTF-8')))
ans = 
    'E2'
    '90'
    '87'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top