true — Create logical arrays filled with true values using MATLAB-compatible size forms.
true creates logical arrays populated with true values across scalar, vector, matrix, and N-D size specifications, matching MATLAB-compatible sizing behavior.
Syntax
L = true()
L = true(n)
L = true(size_vector)
L = true(m, n, ...)
L = true(prototype)
L = true(..., "logical")
L = true(..., "like", prototype)Inputs
n- Type
SizeArg- Required
- Yes
- Description
- Square size.
size_vector- Type
SizeArg- Required
- Yes
- Description
- Size vector defining output dimensions.
dims- Type
SizeArg- Required
- Variadic
- Description
- Dimension sizes.
prototype- Type
LikePrototype- Required
- Yes
- Description
- Prototype value when no numeric dimension arguments are provided.
typename- Type
StringScalar- Required
- No
- Default
"logical"- Description
- Class override keyword (logical).
like_kw- Type
StringScalar- Required
- Yes
- Default
"like"- Description
- Like keyword.
prototype- Type
LikePrototype- Required
- Yes
- Description
- Prototype array used for class/device.
Returns
L- Type
LogicalArray- Description
- Logical output array.
Errors
RunMat:true:TooManyOutputs- When
- More than one output is requested.
- Message
true: too many output arguments
- When
- The 'like' keyword is provided without a prototype argument.
- Message
true: expected prototype after 'like'
- When
- The 'like' keyword is provided multiple times.
- Message
true: multiple 'like' specifications are not supported
Behavior
true() returns the scalar logical true.
true(n) returns an n x n logical array of true values.
true(m, n, ...) returns a logical array with the requested dimensions.
true(sz) accepts a row size vector and returns an array with prod(sz) elements arranged using MATLAB column-major ordering.
true(___, 'like', prototype) uses the preceding size arguments and preserves supported sparse or gpuArray placement from the prototype; the output class remains logical.
All eight integer classes are accepted as exact size controls. Negative signed dimensions produce empty dimensions.
true(A) shape inference, single-precision size controls, resident size controls, and the trailing 'logical' option are optional RunMat language extensions.
GPU residency and provider behavior
A like prototype preserves supported sparse or gpuArray placement while the output class remains logical.
Examples
Creating a 2x3 logical array of true values
mask = true(2, 3)Expected output:
mask = [1 1 1; 1 1 1]Creating a logical array from a size vector
dims = [2 1 3];
mask = true(dims)Expected output:
mask =
2x1x3 logical array
1
1
1
1
1
1Creating a true mask like an existing array
A = rand(3, 2);
mask = true(size(A), 'like', A)Expected output:
mask =
3x2 logical array
1 1
1 1
1 1Using true with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how true changes the result.
Run a small true example, explain the result, then change one input and compare the output.
FAQ
What does true() return?⌄
It returns the logical scalar true.
Does true(n) create a square array?⌄
Yes. true(n) returns an n x n logical array of true values, matching MATLAB behavior.
How does true(sz) interpret a size vector?⌄
A row vector is treated as the full set of dimensions, so true([2 3 4]) yields a 2x3x4 logical array.
Does true keep results on the GPU?⌄
Yes. When a gpuArray is supplied after like, the logical result is allocated through that array's owning provider and remains resident.
Is the 'logical' option required?⌄
No. true always returns logical values. RunMat can accept the redundant option when language extensions are enabled.
Related Array functions
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 · 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 true is executed, line by line, in Rust.
- View the source for true 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.