Using the C++ Math Library    

Assigning to All Elements

Use the colon() index to replace all the elements in a matrix with alternate values. The colon() index, however, is infrequently used in this context because you can accomplish approximately the same result by using an assignment without any indexing. For example, although you can write:

writing

is simpler.

The first statement reuses the storage already allocated for A. The first statement will be slightly slower because the elements from the source must be copied into the destination.


 Assigning to a Subarray Extending Two-Dimensional Assignment to N Dimensions