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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
arguments | Any | Variadic | — | Dimensions, optional class name, and Like/FillValue name-value arguments. |
Returns
| Name | Type | Description |
|---|---|---|
A | Any | Constant-valued output array. |
Errors
| Identifier | When | Message |
|---|---|---|
| — | The fill value is not scalar. | createArray: FillValue must be a scalar |
| — | The fill value type is unsupported. | createArray: unsupported FillValue type |
| — | The 'like' keyword is provided without a prototype argument. | createArray: Like requires a prototype |
| — | The 'like' keyword is provided multiple times. | createArray: Like may be specified only once |
| — | A class keyword and a 'like' prototype are both provided. | createArray: classname and Like cannot be combined |
| — | An unsupported output class is requested. | createArray: unsupported class |
| — | A trailing option string is not recognized. | createArray: unrecognized option |
| — | Dimension arguments fail numeric/shape parsing. | createArray: dimensions must be integer values |
How createArray works
createArrayreturns scalar double zero.createArray(n)creates an n-by-n array andcreateArray(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.
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 · linspace · logspace · magic · meshgrid · nan · nchoosek · ndgrid · nonzeros · ones · peaks · perms · rand · randi · randn · randperm · range · sparse · spdiags · speye · spones · sprand · true · zeros
Grouping
accumarray · combinations · discretize · findgroups · groupcounts · grp2idx · splitapply
Sorting Sets
argsort · intersect · ismember · ismembertol · issorted · issortedrows · setdiff · setxor · sort · sortrows · union · unique
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. 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 an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 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.