

Many MATLAB functions that start with is return logical arrays and are very useful for logical indexing. For example, A(A > 12) extracts all the elements of A that are greater than 12. The output is always in the form of a column vector. MATLAB extracts the matrix elements corresponding to the nonzero values of the logical array. In logical indexing, you use a single, logical array for the matrix subscript. This form of indexed assignment is called scalar expansion.Īnother indexing variation, logical indexing, has proven to be both useful and expressive. V() = 30 % Replace second and third elements by 30 You can always, however, use a scalar on the right side: Usually the number of elements on the right must be the same as the number of elements referred to by the indexing expression on the left. V(end:-1:1) % Reverse the order of elementsīy using an indexing expression on the left side of the equal sign, you can replace certain elements of the vector: V(1:2:end) % Extract all the odd elements

V(2:end-1) % Extract the second through the next-to-last elementsĬombine the colon operator and end to achieve a variety of effects, such as extracting every k-th element or flipping the entire vector: V(5:end) % Extract the fifth through the last elements The special end operator is an easy shorthand way to refer to the last element of v: V2 = v() % Extract and swap the halves of v Swap the two halves of v to make a new vector: V(3:7) % Extract the third through the seventh elements The colon notation in MATLAB provides an easy way to extract a range of elements from v: V() % Extract the first, fifth, and sixth elements Or the subscript can itself be another vector: The matrix analysis functions det, rcond, hess, and expm also show significant increase in speed on large double-precision arrays.Let's start with the simple case of a vector and a single subscript. The matrix multiply (X*Y) and matrix power (X^p) operators show significant increase in speed on large double-precision arrays (on order of 10,000 elements). As a general rule, complicated functions speed up more than simple functions. The operation is not memory-bound processing time is not dominated by memory access time. For example, most functions speed up only when the array contains several thousand elements or more. The data size is large enough so that any advantages of concurrent execution outweigh the time required to partition the data and manage separate execution threads. They should require few sequential operations. These sections must be able to execute with little communication between processes. The function performs operations that easily partition into sections that execute concurrently.
