createArray — Create an array of a specified class and value.
createArray accepts dimensions first, followed by an optional class name and Like or FillValue name-value arguments. Integer dimensions are structural and exact. Integer FillValue and Like forms preserve authoritative class, complexity, and resident storage. The result is complex when either Like or FillValue is complex.
Syntax
X = createArray(sz1, ..., szN, classname?, Like=prototype?, FillValue=value?)Inputs
arguments- Type
Any- Required
- Variadic
- Description
- Dimensions, optional class name, and Like/FillValue name-value arguments.
Returns
A- Type
Any- Description
- Constant-valued output array.
Errors
- When
- The fill value is not scalar.
- Message
createArray: FillValue must be a scalar
- When
- The fill value type is unsupported.
- Message
createArray: unsupported FillValue type
- When
- The 'like' keyword is provided without a prototype argument.
- Message
createArray: Like requires a prototype
Behavior
createArray returns scalar double zero.
createArray(n) creates an n-by-n array and createArray(m,n,...) creates the requested shape.
Negative dimensions are treated as zero.
A trailing class name selects the output class.
FillValue selects the repeated scalar value and preserves its class unless classname or Like requests assignment conversion. Without Like, a GPU-resident FillValue contributes residency and owning provider but does not override an explicit classname.
Like preserves numeric class and GPU residency; classname and Like cannot be combined.
If either Like or FillValue is complex, the output is complex. A real single Like therefore produces complex single for a complex FillValue, while a real double Like produces complex double.
Execution and residency
Like and GPU FillValue forms use the source handle's owning provider for fill and fallback upload paths; native real and paired-complex integer storage remains exact and the output remains on that owner/device.
Examples
Integer array
A = createArray(2,3,'uint64',FillValue=uint64(7));Expected output:
2-by-3 uint64 array of sevensPrototype
A = createArray(2,3,Like=uint16(1),FillValue=8);Expected output:
2-by-3 uint16 arrayComplex FillValue with a real prototype
A = createArray(2,Like=single(0),FillValue=1+2i);Expected output:
2-by-2 complex single arrayUsing createArray with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how createArray changes the result.
Run a small createArray example, explain the result, then change one input and compare the output.
FAQ
How is createArray different from fill?⌄
createArray constructs arrays; fill creates 2-D Patch graphics.
Related Array functions
Creation
colon · 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
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
Combinatorics
Binning
Grouping
Source you can read
Every RunMat function's source is public. Read exactly how createArray is executed, line by line, in Rust.
- View the source for createArray 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.