View all functions

CategoryStrings: Transform

What does the lower function do in MATLAB / RunMat?

lower(text) converts every alphabetic character in text to lowercase. It accepts string scalars, string arrays, character arrays, and cell arrays of character vectors, mirroring MATLAB behaviour. Non-alphabetic characters are returned unchanged.

How does the lower function behave in MATLAB / RunMat?

  • 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.

lower Function GPU Execution Behaviour

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 residency in RunMat (Do I need gpuArray?)

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 of using the lower function in MATLAB / RunMat

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'

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.

See Also

upper, string, char, regexprep, strcmpi

Source & Feedback