1

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?

Community
  • 1
  • 1
Dennis Jaheruddin
  • 21,208
  • 8
  • 66
  • 122
  • how did you even get that character? I tried pasting it from your question, into MATLAB 2012b on Windows, and I am unable to replicate anything you state, except the first and second point – MZimmerman6 Jan 13 '14 at 17:08
  • I'm using Matlab 2013a on ubuntu and I get "Error: The input character is not valid in MATLAB statements or expressions." – Daniel Jan 13 '14 at 17:08
  • I dont know what you expect, this is just another Unicode character outside the range of characters that the command prompt understands: http://www.fileformat.info/info/unicode/char/2407/index.htm. Why do expect it to play a sound at all? – Amro Jan 13 '14 at 17:13
  • @MZimmerman6 That is exactly what I did as well, strange that it results in different responses for you. Perhaps dependant on how the OS is setup? – Dennis Jaheruddin Jan 13 '14 at 17:17
  • @DennisJaheruddin nevermind, I am able to replicate it in Matlab 2012b for Windows. After doing a bit of Googling, BEL is an ANSI character that was used to produce a tone when printed to command prompt. Some OS's no longer do this, but you can still replicate it on windows by opening a command prompt windows, pressing Ctrl+G, and hitting enter. You get that wonderful "bell" tone – MZimmerman6 Jan 13 '14 at 17:28
  • @DennisJaheruddin here is another interesting SO question about it. http://stackoverflow.com/questions/3456138/this-program-sounds-the-bell – MZimmerman6 Jan 13 '14 at 17:30

1 Answers1

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)

bel_symbol

or even get its encoding in say UTF-8:

>> cellstr(dec2hex(unicode2native(c,'UTF-8')))
ans = 
    'E2'
    '90'
    '87'
Amro
  • 123,847
  • 25
  • 243
  • 454
  • related: http://stackoverflow.com/questions/6863147/matlab-how-to-display-utf-8-encoded-text-read-from-file – Amro Jan 13 '14 at 17:34
  • I suppose that it was wishfull thinking that a sound might be played, and the incapability to change it under default settings is comprehensible. However, the difference in behavior between `clear, mean(a)` and `clear, mean(♩)` surprises me. Basically this could mean that if such a char ever appeared in your code, or was accidentally evaluated, it would never throw an error but just hang indefinitely. -- Do you suppose there is anything like `end` that could be entered to 'complete' `mean(♩)`, or would you say it is a bug? – Dennis Jaheruddin Jan 14 '14 at 08:35
  • @DennisJaheruddin: the issue here is that the **command window** (not the MATLAB engine) does not correctly handle input from the entire Unicode character set. As I have shown in the question I linked to, proper Unicode support is still lacking in the MATLAB IDE.. For instance MATLAB refuses to execute an M-file saved in UTF-8 encoding with [BOM marker](https://en.wikipedia.org/wiki/Byte_order_mark), you'll have to work in an external editor to ensure proper encoding (at least that's the case on my Windows machine with the default en-US [locale](https://en.wikipedia.org/wiki/Locale)). – Amro Jan 14 '14 at 17:55
  • To understand what I mean: open [Microsoft Notepad](https://en.wikipedia.org/wiki/Notepad_%28software%29), create a simple script/function (something like `disp('hello world')`), go to "File > Save As..", choose "Unicode" encoding, and save the file as `hello.m`. Try to execute this script in MATLAB or even open it in the builtin editor and you'll see the problem... This basically saves the file in "UTF-16 LE" encoding, which MATLAB apparently does not understand (among other encodings). – Amro Jan 14 '14 at 18:01