lower — Convert text to lowercase in MATLAB and RunMat.
lower(text) converts alphabetic characters in text to lowercase. Supported text containers and non-alphabetic pass-through behavior follow MATLAB semantics.
Syntax
out = lower(str)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
str | Any | Yes | — | String/char/cell text input to transform. |
Returns
| Name | Type | Description |
|---|---|---|
out | Any | Lowercased text preserving input container kind and shape. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:lower:InvalidInput | Input is not a string array, character array, or cell array of text scalars. | lower: first argument must be a string array, character array, or cell array of character vectors |
RunMat:lower:CellElement | Cell array contains a non-text element or non-row char array element. | lower: cell array elements must be string scalars or character vectors |
RunMat:lower:InternalError | Internal output container construction failed. | lower: internal error |
How lower works
- String inputs stay as strings. String arrays preserve their size, orientation, and missing values.
- Character arrays are processed row by row. The result remains a rectangular char array; if any row grows after lowercasing (for example because
'İ'expands), the array widens and shorter rows are padded with spaces. - Cell arrays must contain string scalars or character vectors. The result is a cell array of the same size with each element converted to lowercase, and other types raise MATLAB-compatible errors.
- Missing string scalars (
string(missing)) remain missing and are returned as<missing>. - Inputs that are numeric, logical, structs, or GPU tensors raise MATLAB-compatible type errors.
Does RunMat run lower on the GPU?
lower executes on the CPU. When the input (or any nested element) resides on the GPU, RunMat gathers it to host memory before performing the conversion so results remain identical to MATLAB. Providers do not need to implement custom kernels for this builtin.
GPU memory and residency
RunMat automatically keeps string data on the host for now. If text originates from GPU-based computations (for example as numeric code points stored on the device), lower gathers those values before applying the transformation, so you never need to call gpuArray explicitly for this builtin.
Examples
Convert A String Scalar To Lowercase
txt = "RunMat";
result = lower(txt)Expected output:
result = "runmat"Lowercase Each Element Of A String Array
labels = ["NORTH" "South"; "EaSt" "WEST"];
lowered = lower(labels)Expected output:
lowered = 2×2 string
"north" "south"
"east" "west"Lowercase Character Array Rows While Preserving Shape
animals = char("CAT", "DOGE");
result = lower(animals)Expected output:
result =
2×4 char array
'cat '
'doge'Lowercase A Cell Array Of Character Vectors
C = {'HELLO', 'World'};
out = lower(C)Expected output:
out = 1×2 cell array
{'hello'} {'world'}Keep Missing Strings As Missing
vals = string(["DATA" "<missing>" "GPU"]);
converted = lower(vals)Expected output:
converted = 1×3 string
"data" <missing> "gpu"Lowercase Text Stored On A GPU Input
codes = gpuArray(uint16('RUNMAT'));
txt = char(gather(codes));
result = lower(txt)Expected output:
result = 'runmat'Using lower with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how lower changes the result.
Run a small lower example, explain the result, then change one input and compare the output.
FAQ
Does lower change non-alphabetic characters?⌄
No. Digits, punctuation, whitespace, and symbols remain untouched. Only alphabetic code points that have distinct lowercase forms are converted.
What happens to character array dimensions?⌄
RunMat lowers each row independently and pads with spaces when a lowercase mapping increases the row length. This mirrors MATLAB’s behaviour so the result always has rectangular dimensions.
Can I pass numeric arrays to lower?⌄
No. Passing numeric, logical, or struct inputs raises a MATLAB-compatible error. Convert the data to a string or character array first (for example with string or char).
How are missing strings handled?⌄
Missing string scalars remain <missing> and are returned unchanged. This matches MATLAB’s handling of missing values in text processing functions.
Will lower ever execute on the GPU?⌄
Not today. The builtin gathers GPU-resident data automatically and performs the conversion on the CPU so the results match MATLAB exactly. Providers may add device-side kernels in the future, but the behaviour will stay compatible.
Related Strings functions
Transform
erase · eraseBetween · extractBetween · join · pad · replace · split · strcat · strip · strjoin · strrep · strsplit · strtrim · upper
Core
char · compose · num2str · sprintf · str2double · strcmp · strcmpi · string · string.empty · strings · strlength · strncmp
Search
contains · endsWith · startsWith · strfind
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how lower is executed, line by line, in Rust.
- View the source for lower 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.