true — Create logical arrays filled with true values.
true creates logical arrays filled with true values. RunMat mirrors MATLAB sizing semantics across scalar, vector, matrix, and N-D forms.
How does the true function behave in MATLAB / RunMat?
true()returns the scalar logicaltrue.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 size vector (row or column) and returns an array with prod(sz) elements arranged using MATLAB column-major ordering.true(A)returns a logical array of true with the same size asA.true(___, 'like', prototype)uses the prototype only for sizing; the result is still a host logical array.true(___, 'logical')is accepted for MATLAB compatibility and has no effect.
Examples of using true in MATLAB / RunMat
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 with the same size as an existing array
A = rand(3, 2);
mask = true(A)Expected output:
mask =
3x2 logical array
1 1
1 1
1 1FAQ
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 or column 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?
No. The builtin always returns a host logical array. gpuArray inputs are only used to infer the output size.
Is the 'logical' option required?
No. true always returns logical values; the 'logical' option is accepted only for MATLAB compatibility.
See also
false, logical, islogical, zeros
Source & Feedback
- Source code: `crates/runmat-runtime/src/builtins/array/creation/true_false.rs`
- Found a bug? Open an issue with a minimal reproduction.