ismatrix — Determine whether an array has matrix geometry.
ismatrix returns one host logical scalar when the MATLAB-visible rank is at most two.
Syntax
tf = ismatrix(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 when the MATLAB-visible rank is at most two.
Errors
RunMat:ismatrix:InternalError- When
- Value or distributed shape metadata is invalid.
- Message
ismatrix: invalid shape metadata
RunMat:ismatrix:TooManyOutputs- When
- More than one output is requested.
- Message
ismatrix: too many output arguments
Matrix geometry
ismatrix(A) is true when the MATLAB-visible rank is at most two. Scalars, row and column vectors, and ordinary two-dimensional arrays are matrices. The rule applies across numeric, logical, character, string, cell, struct, object, sparse, and complex arrays.
Empty arrays with at most two visible dimensions are matrices. An empty or populated array with a nonsingleton third or later dimension is not.
Trailing dimensions and residency
Trailing singleton dimensions do not increase MATLAB-visible rank, so 2-by-3-by-1 and 1-by-1-by-1 remain matrices. A nonsingleton later dimension makes the result false.
gpuArray and distributed values are classified from validated shape metadata without launching kernels or transferring payload data. The result is a host logical scalar.
Examples
Check a two-dimensional matrix
tf = ismatrix([1 2 3; 4 5 6])Expected output:
tf = trueCheck scalars and vectors
scalar = ismatrix(42);
row = ismatrix(1:5);
column = ismatrix((1:5)')Expected output:
All results are trueReject a three-dimensional array
tf = ismatrix(ones(2, 2, 3))Expected output:
tf = falseCompare empty shapes
plain = ismatrix([]);
row = ismatrix(zeros(1, 0));
column = ismatrix(zeros(0, 1));
higher = ismatrix(zeros(0, 0, 3))Expected output:
The first three are true; higher is falseIgnore trailing singleton dimensions
tf = ismatrix(ones(2, 3, 1, 1))Expected output:
tf = trueUse cell and string arrays
cells = ismatrix({1, 2; 3, 4});
strings = ismatrix(["a" "b" "c"])Expected output:
Both results are trueInspect a resident matrix
G = gpuArray(ones(4, 4));
tf = ismatrix(G)Expected output:
tf = trueUsing ismatrix with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how ismatrix changes the result.
Run a small ismatrix example, explain the result, then change one input and compare the output.
FAQ
Are scalars and vectors matrices?⌄
Yes. They all have at most two visible dimensions.
Do trailing singleton dimensions matter?⌄
No. They do not increase MATLAB-visible rank. A nonsingleton third or later dimension does.
Are empty arrays matrices?⌄
Two-dimensional empty shapes are matrices; a nonsingleton later dimension makes an empty array nonmatrix.
Does gpuArray input gather?⌄
No. RunMat reads the required dimensions from the handle and returns a host logical scalar.
Related Array functions
Introspection
height · iscolumn · isempty · isrow · isscalar · isvector · 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 ismatrix is executed, line by line, in Rust.
- View the source for ismatrix 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.