RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.1, Nov 17, 2026

RunMat® is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
See all docs
Builtin Reference
    • height
    • iscolumn
    • isempty
    • ismatrix
    • isrow
    • isscalar
    • isvector
    • length
    • ndims
    • numel
    • size
    • width

size — Return array dimension sizes in vector or multiple-output forms.

size reads outer array shape metadata, supports scalar, vector, and separate dimension queries, and implements requested-output collapse rules.

Syntax

sz = size(A)
sz = size(A, dim)
sz = size(A, dim1, dim2, ...)
[sz1, ..., szN] = size(A)
[sz1, ..., szN] = size(A, dim1, ..., dimN)

Inputs

A
Type
Any
Required
Yes
Description
Value whose MATLAB-visible dimensions are inspected.
dim
Type
SizeArg
Required
Variadic
Description
Positive integer scalar selectors, or one vector or empty selector.
NameTypeRequiredDefaultDescription
AAnyYes—Value whose MATLAB-visible dimensions are inspected.
dimSizeArgVariadic—Positive integer scalar selectors, or one vector or empty selector.

Returns

sz
Type
NumericArray
Description
Host double row vector containing the queried dimension extents.
sz
Type
NumericScalar
Description
Host double scalar for each requested output.
NameTypeDescription
szNumericArrayHost double row vector containing the queried dimension extents.
szNumericScalarHost double scalar for each requested output.

Returned values from size depend on how many outputs the caller requests.

Errors

RunMat:size:InvalidDimensionType
When
A selector is not a numeric scalar or vector.
Message
size: dimension selectors must be numeric scalars or one numeric vector
RunMat:size:InvalidDimensionVector
When
The single vector selector is not vector-shaped.
Message
size: dimension selector must be a vector
RunMat:size:InvalidDimensionList
When
A vector occurs within a variadic scalar selector list.
Message
size: separate dimension arguments must be scalars
IdentifierWhenMessage
RunMat:size:InvalidDimensionTypeA selector is not a numeric scalar or vector.size: dimension selectors must be numeric scalars or one numeric vector
RunMat:size:InvalidDimensionVectorThe single vector selector is not vector-shaped.size: dimension selector must be a vector
RunMat:size:InvalidDimensionListA vector occurs within a variadic scalar selector list.size: separate dimension arguments must be scalars
RunMat:size:NonFiniteDimensionA floating selector is not finite.size: dimension must be finite
RunMat:size:NonIntegerDimensionA floating selector is fractional.size: dimension must be an integer
RunMat:size:NonPositiveDimensionA selector is less than one.size: dimension must be at least one
RunMat:size:DimensionOutOfRangeA selector is outside the unsigned structural range.size: dimension is outside the supported structural range
RunMat:size:OutputCountMismatchThe number of outputs does not equal the number of explicit queried dimensions.size: output count must match queried dimension count
RunMat:size:ResultNotExactDoubleA result extent or collapsed product is not exactly representable as double.size: result exceeds exact double range
RunMat:size:InternalErrorShape metadata is invalid or output construction fails.size: invalid shape metadata

Dimension queries

size(A) returns the complete MATLAB-visible shape as a 1-by-N host double row vector. Scalars and string scalars have shape 1-by-1; character vectors retain their character-array shape; cells, structs, object arrays, tables, and timetables report their outer array dimensions.

size(A, dim) returns one extent. A vector selects several dimensions, an empty vector returns a 1-by-0 row, and separate scalar arguments select several dimensions. A selector beyond the visible rank contributes 1. The vector and separate-argument forms are available in the compatible language surface introduced in R2019b.

Multiple outputs

With no explicit dimensions, multiple outputs receive leading dimensions separately. If fewer outputs than visible dimensions are requested, the final output is the checked product of every remaining dimension. Extra outputs are padded with 1.

With explicit queried dimensions, the number of outputs must equal the number of queried dimensions. Every output is a host double scalar.

Exact structural values

All fixed-width integer selector classes are decoded from native storage without conversion through double. Extents, selected dimensions, and collapsed products use checked structural arithmetic. RunMat reports an error instead of rounding a structural result that cannot be represented exactly by the documented double output.

gpuArray and distributed inputs are inspected through validated handle metadata. size launches no kernel, calls no acceleration provider, transfers no payload, and returns host values at a fusion boundary.

Examples

Read a matrix shape

A = [1 2 3; 4 5 6];
sz = size(A)

Expected output:

sz = [2 3]

Read one dimension

A = randn(8, 4);
rows = size(A, 1)

Expected output:

rows = 8

Read selected dimensions

A = zeros(5, 4, 3);
selected = size(A, [1 3])

Expected output:

selected = [5 3]

Use separate dimension selectors

A = zeros(5, 4, 3);
selected = size(A, 2, 3)

Expected output:

selected = [4 3]

Collapse trailing dimensions into the final output

A = zeros(3, 4, 5);
[first, remainder] = size(A)

Expected output:

first = 3; remainder = 20

Return an empty dimension query

A = ones(2, 3);
sz = size(A, [])

Expected output:

sz is a 1-by-0 double array

Inspect a cell array

C = {1, 2, 3; 4, 5, 6};
sz = size(C)

Expected output:

sz = [2 3]

Inspect a resident array without gathering

G = gpuArray(ones(256, 512));
sz = size(G)

Expected output:

sz = [256 512]

Using size with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how size changes the result.

Run a small size example, explain the result, then change one input and compare the output.

FAQ

How is size different from length and numel?⌄

size exposes individual dimensions, length returns the largest dimension, and numel returns the product of all dimensions.

What happens when a selector exceeds the array rank?⌄

The corresponding result is 1.

How are row and column vectors reported?⌄

A row vector is 1-by-N and a column vector is N-by-1.

What happens for empty arrays?⌄

Zero extents remain present in the returned shape and participate in collapsed products.

Can dimensions be queried as a vector or list?⌄

Yes. A vector or separate positive integer scalar selectors return the corresponding extents in order.

Does size gather gpuArray or distributed data?⌄

No. Complete shape metadata is part of each validated handle.

Where does the result live?⌄

All size outputs are host double values because they describe metadata, not array payload.

Related Array functions

Introspection

height · iscolumn · isempty · ismatrix · isrow · isscalar · isvector · length · ndims · numel · width

Accumulation

accumarray

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

combinations · nchoosek · perms

Binning

discretize

Indexing

find · ind2sub · sub2ind

Grouping

findgroups · groupcounts · grp2idx · splitapply

Source you can read

Every RunMat function's source is public. Read exactly how size is executed, line by line, in Rust.

  • View the source for size 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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • Dimension queries
  • Multiple outputs
  • Exact structural values
  • Examples
  • Read a matrix shape
  • Read one dimension
  • Read selected dimensions
  • Use separate dimension selectors
  • Collapse trailing dimensions into the final output
  • Return an empty dimension query
  • Inspect a cell array
  • Inspect a resident array without gathering
  • Using size with coding agents
  • FAQ
  • Related Array functions
  • Introspection
  • Accumulation
  • Sorting Sets
  • Shape
  • Creation
  • Combinatorics
  • Binning
  • Indexing
  • Grouping
  • Source you can read
  • About RunMat