Using Greek alphabet (or any non-ANSI alphabet) as variable names in MATLAB

11,496

Solution 1

It is not possible.

I refer to the following part of Matlab documentation:

Valid Names

A valid variable name starts with a letter, followed by letters, digits, or underscores. MATLAB is case sensitive, so A and a are not the same variable. The maximum length of a variable name is the value that the namelengthmax command returns.

Letter is defined as ANSI character between a-z and A-Z. For example, the following hebrew letter Aleph returns false (in Matlab R2018a returns true):

isletter('א')

By the way, you can always check whether your variable name is fine by using genvarname.

genvarname('א')

ans =

x0x1A

Solution 2

While Andrey's answer is true for variable names it's a different story for figures.

title('\epsilon\omega') will actually work and generate an epsilon and an omega as title (although the matlab font replaces them with different symbols). If you export the figure as an eps or pdf file you will see that the title really is epsilon omega. Actually any LaTeX control sequence will work!

Same is true for all the figure text objects such as legends and axis labels.

Share:
11,496
user1508419
Author by

user1508419

Updated on June 04, 2022

Comments

  • user1508419
    user1508419 almost 2 years

    Is it possible using Greek alphabet to represent variables in MATLAB?

    For example, I'd like to use the Greek character epsilon as a variable in MATLAB. I tried to insert \epsilon but I received an error.

  • John Alexiou
    John Alexiou over 8 years
    I think MuPad (which is not part of matlab) accepts greek variables and you can import them into the command environment as symbolic variables.
  • Cris Luengo
    Cris Luengo about 5 years
    @MartinG: Though isletter now returns true for letters of other alphabets, these still are not legal as variable names.
  • Martin G
    Martin G about 5 years
    @CrisLuengo Agree, but my edit adds valid information for the given isletter example