
Solving Problems with Vectorization É 273
If your program changes the data type or array shape of an existing variable, MATLAB must
temporarily stop its code acceleration process and handle the change. For example, this code
changes the type of X from double to char, and thus slows the acceleration process.
X = 90;
.
-accelerated code-
.
X = ‘A’; % This line breaks accelerated region
9.5 Solving Problems with Vectorization
The above concepts of indexing, preallocation, and vectorization are applicable to several prob-
lems. Three representative problems are considered here to illustrate their utility.
Example 9.15
Single loop summation function.