3. Distinctive Features of MATLAB
Society for Industrial and Applied Mathematics eBooks · 2005
MATLAB has three features that distinguish it from most other modern programming languages and problem solving environments. We introduce them in this chapter and elaborate on them later in the book. 3.1. Automatic Storage Allocation As we saw in Chapter 2, variables are not declared prior to being assigned. This applies to arrays as well as scalars. Moreover, MATLAB automatically expands the dimensions of arrays in order for assignments to make sense. Thus, starting with an empty workspace, we can set up a 1-by-3 vector x of zeros with ≫ x(3) = 0 x = 0 0 0 and then expand it to length 6 with ≫ x(6) = 0 x = 0 0 0 0 0 0 MATLAB's automatic allocation of storage is one of its most convenient and distinctive features. 3.2. Variable Arguments Lists MATLAB contains a large (and user-extendible) collection of functions. They take zero or more input arguments and return zero or more output arguments. MATLAB enforces a clear distinction between input and output: input arguments appear on the right of the function name, within parentheses, and output arguments appear on the left, within square brackets. Functions can support a variable number of input and output arguments, so that on a given call not all arguments need be supplied. Functions can even vary their behavior depending on the precise number and type of arguments supplied. We illustrate with some examples.