ismatrix
Determine whether input is matrix
Syntax
Description
Examples
Arrays of Different Sizes
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 = logical
1
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 = logical
1
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 = logical
0
Determine Matrix from Three-Dimensional Array
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×3
0.1000 0.2000 0.5000
0.3000 0.6000 0.4000
TF = ismatrix(A)
TF = logical
1
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(:,:,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 = logical
0
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.
TF = ismatrix(A(:,:,2))
TF = logical
1
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.
TF = ismatrix(A(2,:,:))
TF = logical
0
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.
Determine Matrix from Character Vector and String
Create an array of characters. Determine whether it is a matrix.
A = 'Hello, World!';
TF = ismatrix(A)
TF = logical
1
Check the dimension of A
using size
. A
is a matrix of size 1-by-13.
size(A)
ans = 1×2
1 13
Now create a string scalar by enclosing a piece of text in double quotes.
A = "Hello, World!";
Check whether the scalar A
of size 1-by-1 is also a matrix.
TF = ismatrix(A)
TF = logical
1
Input Arguments
A
— Input array
scalar | vector | matrix | multidimensional array
Input array, specified as a scalar, vector, matrix, or multidimensional array.
Extended Capabilities
Tall Arrays
Calculate with arrays that have more rows than fit in memory.
The
ismatrix
function fully supports tall arrays. For more information,
see Tall Arrays.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
The ismatrix
function
fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray
(Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced in R2010b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)