Page 104 - Basics of MATLAB and Beyond
P. 104
>>a=[123;4 56;789]
a =
1 2 3
4 5 6
7 8 9
>> a(:,:,2) = a*2
a(:,:,1) =
1 2 3
4 5 6
7 8 9
a(:,:,2) =
2 4 6
8 10 12
14 16 18
>> a(:,:,3) = eye(3)
a(:,:,1) =
1 2 3
4 5 6
7 8 9
a(:,:,2) =
2 4 6
8 10 12
14 16 18
a(:,:,3) =
1 0 0
0 1 0
0 0 1
Multidimensional arrays must be full N-rectangles; that is, they must
have the same number of elements in parallel dimensions: all rows must
have the same number of columns, all “pages” must have the same num-
ber of rows and columns, etc.
If you assign a single value to a matrix, matlab expands the defini-
tion as you would expect:
>> a(:,:,3) = 3
a(:,:,1) =
1 2 3
4 5 6
7 8 9
a(:,:,2) =
2 4 6
8 10 12
14 16 18
c 2000 by CRC Press LLC