Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to display unicode in MATLAB plot labels?

Tags:

unicode

matlab

I would like to call something like

xlabel( 'Time (μs)' );  

But that just shows up with a question mark on the plot. Is there anyway to have the unicode show up?

like image 748
Shea Levy Avatar asked Apr 13 '11 14:04

Shea Levy


3 Answers

For your specific example, you can get the display you want using TeX\LaTeX formatting:

xlabel('Time ({\mu}s)');

For the more general case of displaying Unicode characters, if you know the code for your character you can convert the decimal value for the code to a character using the function char and build a string like so:

xlabel(['Time (' char(181) 's)']);  % Same results as above
like image 75
gnovice Avatar answered Oct 20 '22 02:10

gnovice


Try this instead:

 xlabel( 'Time (\mu s)',  'interpreter','tex' );

or simply

xlabel( 'Time (\mu s)');
like image 33
Itamar Katz Avatar answered Oct 20 '22 03:10

Itamar Katz


I'd prefer TeX\LaTeX formatting.

In general MATLAB does not have a consistent system for displaying Unicode characters. In his answer gnovice mentions using the char function but beware that this will actually display whatever character corresponds to that decimal value on your current system (based on your Locale).

On Windows that means you'll probably actually want to reference the Windows-1252 code page when choosing your decimal value. You can use this resource if you decide to use LaTeX.

like image 40
davidvandebunte Avatar answered Oct 20 '22 03:10

davidvandebunte