Skip to main content

3.3) Naming Conventions


  1. Variables must start with a letter and can be up to 64 characters long. Trailing characters can be letters, numbers or underscores
  2. Variable names are case-sensitive, so "a" and "A" represent different variables as do "var" and "Var"
  3. It is good programming practice to use meaningful variable names. For example, "lat", "time" and "dt" are more meaningful than "x", "y" and "z".
  4. Variable names should not coincide with Matlab function names (including user-defined function names). For example:
  5. [matlab]
    >> sin=4*4
    [/matlab]

    is a poor choice of variable name as "sin" is a built-in Matlab function. Note that the above won't fail; it will instead override the function "sin" with the variable '16'. You will subsequently be unable to use "sin" as a trigonometric function.

  6. Avoid using "i" and "j" for variables - these are commonly used in loops. Also if you are using complex numbers, it may lead to confusion.

Matlab stores variables in a part of memory called the workspace.

Remember that "ans" is the default variable when the result of a calculation isn't assigned to a variable.