Desktop Tools and Development Environment Previous page   Next Page

Case and Space Sensitivity

Uppercase and Lowercase for Variables

With respect to case, MATLAB requires an exact match for variable names. For example, if you have a variable a, you cannot refer to that variable as A.

Uppercase and Lowercase for Files and Functions

With respect to functions, filenames, objects, and classes on the search path or in the current directory, MATLAB prefers an exact match with regard to case. MATLAB runs a function if you do not enter the function name using the exact case, but displays a warning the first time you do this.

To avoid ambiguity and warning messages, always match the case exactly. It is a best practice to use lowercase only when running and naming functions. This is especially useful when you use both Windows and UNIX platforms because their file systems behave differently with regard to case.

Note that if you use the help function, function names are shown in all uppercase, for example, PLOT, solely to distinguish them. Some functions for interfacing to Java do use mixed case and the M-file help and documentation accurately reflect that.

Examples.   The directory first is at the top of the search path and contains the file A.m. If you type a instead of A, MATLAB runs A.m but issues a warning. When you type a again during that session, MATLAB runs A.m but does not show the warning.

Add the directory second after first on the search path, with the file a.m in second. The directory first contains A.m, while second contains a.m Type a. MATLAB runs a.m but displays a warning the first time you do this.

Spaces in Expressions

Blank spaces around operators such as -, :, and ( ), are optional, but they can improve readability. For example, MATLAB interprets the following statements the same way.

y = sin (3 * pi) / 2
y=sin(3*pi)/2

Previous page  Controlling Input Syntax Highlighting Next page

© 1994-2005 The MathWorks, Inc.