Create a 3-D array and determine whether the array elements are a matrix.
First define a 2-D array of size 2-by-3. Determine whether it is a matrix.
A = 2×3
0.1000 0.2000 0.5000
0.3000 0.6000 0.4000
To create a 3-D array, add a third dimension to the array A
. Assign another 2-by-3 matrix to the third dimension of A
with index value 2.
A =
A(:,:,1) =
0.1000 0.2000 0.5000
0.3000 0.6000 0.4000
A(:,:,2) =
1 1 1
1 1 1
Check whether the 3-D array of size 2-by-3-by-2 is a matrix.
Now determine whether the array elements of A
are a matrix. Check whether the second page of the 3-D array is a matrix. The syntax A(:,:,2)
uses a colon in the first and second dimensions to access all rows and all columns.
Check whether the second row of the 3-D array is a matrix. The syntax A(2,:,:)
uses a colon in the second and third dimensions to include all columns and all pages.
A(:,:,2)
is a matrix since it is a multidimensional array of size 2-by-3. However, A(2,:,:)
is not a matrix since it is a multidimensional array of size 1-by-3-by-2.