11

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?

user3666197
  • 1
  • 6
  • 50
  • 92
Shea Levy
  • 5,237
  • 3
  • 31
  • 42
  • 2
    For the more general case of Unicode which isn't available through MATLAB's limited LaTeX capabilities, see http://stackoverflow.com/questions/7014476/is-it-possible-to-print-unicode-text-or-characters-in-matlab and http://stackoverflow.com/questions/6863147/matlab-how-to-display-utf-8-encoded-text-read-from-file – Jonas Heidelberg Aug 10 '11 at 18:35

3 Answers3

13

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
gnovice
  • 125,304
  • 15
  • 256
  • 359
  • 2
    BTW, you don't need the curly brackets around \mu. `\mus` will work. – Jonas Apr 13 '11 at 19:06
  • 1
    @Jonas: True. Somehow a while ago I got into the habit of using curly braces to group TeX symbols, but I don't really remember *why*. Maybe it was just to set it apart from the regular text and make it easier to read, or maybe to account for the off chance that the TeX symbol and regular string combination might give me a different TeX symbol. Old habits... ;) – gnovice Apr 13 '11 at 19:46
3

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.

davidvandebunte
  • 1,286
  • 18
  • 25
3

Try this instead:

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

or simply

xlabel( 'Time (\mu s)');
Itamar Katz
  • 9,544
  • 5
  • 42
  • 74
  • Thanks, this worked for what I wanted. I'm leaving the question open because it doesn't seem like arbitrary unicode can be displayed in this way (though I may be wrong on this). – Shea Levy Apr 13 '11 at 15:00
  • Quick note: I actually wanted \mus not \mu s, I don't want a space between the μ and the s. – Shea Levy Apr 13 '11 at 15:04
  • 2
    the space is only for the tex interpreter to identify the symbol, the output should not contain a space. – Itamar Katz Apr 17 '11 at 09:27