Main Content

isvector

Determine whether input is vector

Description

example

TF = isvector(A) returns logical 1 (true) if A is a vector. Otherwise, it returns logical 0 (false). A vector is a two-dimensional array that has a size of 1-by-N or N-by-1, where N is a nonnegative integer.

Examples

collapse all

Create a 2-by-2 matrix. Determine whether it is a vector.

A = [1 2; 3 4];
TF = isvector(A)
TF = logical
   0

Check whether the first column of the matrix is a vector.

TF = isvector(A(:,1))
TF = logical
   1

Check whether the first row of the matrix is a vector.

TF = isvector(A(1,:))
TF = logical
   1

Create a scalar, which is a 1-by-1 array.

A = 5;

Determine whether the scalar A is also a vector.

TF = isvector(A)
TF = logical
   1

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

A = 'Hello, World!';
TF = isvector(A)
TF = logical
   1

Check the dimension of A using size. A is a 1-by-13 character vector.

sz = size(A)
sz = 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 is also a vector.

TF = isvector(A)
TF = logical
   1

Input Arguments

collapse all

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

Algorithms

  • If the input array A has more than two dimensions, then isvector(A) always returns logical 0 (false). For example, an array of size 1-by-1-by-N is not a vector.

  • isvector(A) function does not have any special behavior for dimension lengths equal to 0. For example, isvector(A) returns logical 1 (true) if the size of A is 0-by-1. But, isvector(A) returns logical 0 (false) if the size of A is 0-by-3.

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™.

HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.

Version History

Introduced before R2006a