3.3) Naming Conventions
- Variables must start with a letter and can be up to 64 characters long. Trailing characters can be letters, numbers or underscores
- Variable names are case-sensitive, so "a" and "A" represent different variables as do "var" and "Var"
- It is good programming practice to use meaningful variable names. For example, "lat", "time" and "dt" are more meaningful than "x", "y" and "z".
- Variable names should not coincide with Matlab function names (including user-defined function names). For example:
- 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]
>> 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.
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.