isvector — Determine whether an array has vector geometry.
isvector returns one host logical scalar for a visible 1-by-N or N-by-1 shape.
Syntax
tf = isvector(A)Inputs
A- Type
Any- Required
- Yes
- Description
- Value whose MATLAB-visible dimensions are inspected.
Returns
tf- Type
LogicalArray- Description
- Logical scalar that is true for a visible 1-by-N or N-by-1 shape.
Errors
RunMat:isvector:InternalError- When
- Value or distributed shape metadata is invalid.
- Message
isvector: invalid shape metadata
RunMat:isvector:TooManyOutputs- When
- More than one output is requested.
- Message
isvector: too many output arguments
Vector geometry
isvector(A) is true for 1-by-N and N-by-1 visible shapes, including scalars. It applies the same rule to numeric, logical, character, string, cell, struct, object, sparse, and complex arrays.
Empty 1-by-0 and 0-by-1 arrays are vectors; an empty 0-by-3 array is not. A matrix with both visible dimensions greater than one is not a vector.
Higher dimensions
MATLAB-visible rank ignores trailing singleton dimensions. Shapes such as 3-by-1-by-1 and 1-by-3-by-1 remain vectors. A nonsingleton third or later dimension makes the result false.
gpuArray and distributed inputs are classified from validated shape metadata without kernels or payload transfers. The result is one host logical scalar.
Examples
Check a row vector
tf = isvector([1 2 3])Expected output:
tf = trueReject a matrix
tf = isvector([1 2 3; 4 5 6])Expected output:
tf = falseTreat a scalar as a vector
tf = isvector(42)Expected output:
tf = trueCompare empty vector shapes
row = isvector(zeros(1, 0));
column = isvector(zeros(0, 1));
wide = isvector(zeros(0, 3))Expected output:
row and column are true; wide is falseIgnore trailing singleton dimensions
tf = isvector(ones(3, 1, 1))Expected output:
tf = trueReject a nonsingleton third dimension
tf = isvector(ones(1, 1, 4))Expected output:
tf = falseCheck character and string rows
tf_char = isvector('RunMat');
tf_strings = isvector(["a" "b" "c"])Expected output:
Both results are trueInspect a resident column vector
G = gpuArray((1:5)');
tf = isvector(G)Expected output:
tf = trueUsing isvector with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how isvector changes the result.
Run a small isvector example, explain the result, then change one input and compare the output.
FAQ
Are scalars vectors?⌄
Yes. A scalar has visible shape 1-by-1.
Which empty arrays are vectors?⌄
1-by-0 and 0-by-1 are vectors; shapes such as 0-by-3 are not.
Do trailing singleton dimensions matter?⌄
No. They do not increase MATLAB-visible rank. A nonsingleton third or later dimension does.
Do cells, structs, strings, sparse arrays, and gpuArrays use different rules?⌄
No. Their visible dimensions enter the same shape predicate; resident payloads are not transferred.
Related Array functions
Introspection
height · iscolumn · isempty · ismatrix · isrow · isscalar · length · ndims · numel · size · width
Accumulation
Sorting Sets
argsort · intersect · ismember · ismembertol · issorted · issortedrows · setdiff · setxor · sort · sortrows · union · unique
Shape
blkdiag · cat · circshift · diag · flip · fliplr · flipud · horzcat · ipermute · kron · permute · repelem · repmat · reshape · rot90 · shiftdim · squeeze · toeplitz · tril · triu · vertcat
Creation
colon · createArray · empty · eye · false · full · inf · int16.empty · int32.empty · int64.empty · int8.empty · linspace · logspace · magic · meshgrid · nan · ndgrid · nonzeros · ones · peaks · rand · randi · randn · randperm · range · sparse · spdiags · speye · spones · sprand · true · uint16.empty · uint32.empty · uint64.empty · uint8.empty · zeros
Combinatorics
Binning
Grouping
Source you can read
Every RunMat function's source is public. Read exactly how isvector is executed, line by line, in Rust.
- View the source for isvector in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.