isscalar — Determine whether a value has scalar geometry.
isscalar returns one host logical scalar from the input's MATLAB-visible shape.
Syntax
tf = isscalar(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 every visible dimension is one.
Errors
RunMat:isscalar:InternalError- When
- Value or distributed shape metadata is invalid.
- Message
isscalar: invalid shape metadata
RunMat:isscalar:TooManyOutputs- When
- More than one output is requested.
- Message
isscalar: too many output arguments
Scalar shape
isscalar(A) is true when A contains exactly one element and every MATLAB-visible dimension is one. Numeric, logical, complex, string, cell, struct, and object values use the same shape rule.
Empty arrays and vectors with more than one element return false. A character value must contain exactly one character; a string scalar remains scalar even when its text is empty.
Trailing dimensions and residency
Trailing singleton dimensions do not change MATLAB-visible scalar geometry. A shape such as 1-by-1-by-1 is scalar, while any nonsingleton dimension makes the result false.
gpuArray and distributed inputs are classified from validated shape metadata. The predicate does not launch a kernel or transfer payload data, and returns a host logical scalar.
Examples
Check a numeric scalar
tf = isscalar(42)Expected output:
tf = trueReject a row vector
tf = isscalar([1 2 3])Expected output:
tf = falseCompare string and character shapes
tf_string = isscalar("hello");
tf_char = isscalar('h');
tf_char_row = isscalar('runmat')Expected output:
The string and one character are scalar; the character row is notReject an empty array
tf = isscalar([])Expected output:
tf = falseCheck a one-element cell
C = {pi};
tf = isscalar(C)Expected output:
tf = trueInspect a resident scalar shape
G = gpuArray(ones(1, 1));
tf = isscalar(G)Expected output:
tf = trueUsing isscalar with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how isscalar changes the result.
Run a small isscalar example, explain the result, then change one input and compare the output.
FAQ
Does isscalar([]) return true?⌄
No. An empty array contains zero elements.
Is an empty string scalar?⌄
Yes. Its container shape is 1-by-1 regardless of its text content.
Are 1-by-1-by-1 arrays scalar?⌄
Yes. Trailing singleton dimensions do not change MATLAB-visible scalar geometry.
Does gpuArray input launch a kernel?⌄
No. RunMat reads the handle shape and returns a host logical scalar.
Related Array functions
Introspection
height · iscolumn · isempty · ismatrix · isrow · 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 isscalar is executed, line by line, in Rust.
- View the source for isscalar 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.