Main Content

ismatrix

Determine whether input is matrix

Description

example

TF = ismatrix(A)returns logical1(true) ifAis a matrix. Otherwise, it returns logical0(false). A matrix is a two-dimensional array that has a size ofm-by-n, wheremandnare nonnegative integers.

Examples

collapse all

Determine whether arrays of different sizes are matrices.

Create an array of size 1-by-3. Determine whether it is a matrix.

A1 = zeros(1,3); TF = ismatrix(A1)
TF =logical1

Create an empty array of size 0-by-3. Determine whether it is a matrix. A 2-D empty array is a matrix.

A2 = zeros(0,3); TF = ismatrix(A2)
TF =logical1

Create an array of size 1-by-3-by-2. Determine whether it is a matrix. A 3-D array is not a matrix.

A3 = zeros(1,3,2); TF = ismatrix(A3)
TF =logical0

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 = [0.1 0.2 0.5; 0.3 0.6 0.4]
A =2×30.1000 0.2000 0.5000 0.3000 0.6000 0.4000
TF = ismatrix(A)
TF =logical1

To create a 3-D array, add a third dimension to the arrayA. Assign another 2-by-3 matrix to the third dimension ofAwith index value 2.

A(:,:,2) = ones(2,3)
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.

TF = ismatrix(A)
TF =logical0

Now determine whether the array elements ofAare a matrix. Check whether the second page of the 3-D array is a matrix. The syntaxA(:,:,2)uses a colon in the first and second dimensions to access all rows and all columns.

TF = ismatrix(A(:,:,2))
TF =logical1

Check whether the second row of the 3-D array is a matrix. The syntaxA(2,:,:)uses a colon in the second and third dimensions to include all columns and all pages.

TF = ismatrix(A(2,:,:))
TF =logical0

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.

Create an array of characters. Determine whether it is a matrix.

A ='Hello, World!'; TF = ismatrix(A)
TF =logical1

Check the dimension ofAusingsize.Ais a matrix of size 1-by-13.

size(A)
ans =1×21 13

Now create a string scalar by enclosing a piece of text in double quotes.

A ="Hello, World!";

检查是否标量Aof size 1-by-1 is also a matrix.

TF = ismatrix(A)
TF =logical1

Input Arguments

collapse all

Input array, specified as a scalar, vector, matrix, or multidimensional array.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

版本历史

Introduced in R2010b