Main Content

Case and Space Sensitivity

MATLAB® code is sensitive to casing, and insensitive to blank spaces except when defining arrays.

Uppercase and Lowercase

In MATLAB code, use an exact match with regard to case for variables, files, and functions. For example, if you have a variable, a, you cannot refer to that variable as A. It is a best practice to use lowercase only when naming functions. This is especially useful when you use both Microsoft® Windows® and UNIX®1 platforms because their file systems behave differently with regard to case.

When you use the help function, the help displays some function names in all uppercase, for example, PLOT, solely to distinguish the function name from the rest of the text. Some functions for interfacing to Oracle® Java® software do use mixed case and the command-line help and the documentation accurately reflect that.

Spaces

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

However, blank spaces act as delimiters in horizontal concatenation. When defining row vectors, you can use spaces and commas interchangeably to separate elements:

A = [1, 0 2, 3 3]
A =

     1     0     2     3     3
Because of this flexibility, check to ensure that MATLAB stores the correct values. For example, the statement [1 sin (pi) 3] produces a much different result than [1 sin(pi) 3] does.
[1 sin (pi) 3]
Error using sin
Not enough input arguments.
[1 sin(pi) 3]
ans =

    1.0000    0.0000    3.0000


1 UNIX is a registered trademark of The Open Group in the United States and other countries.