RunMat
GitHub

strcmpi — Compare text inputs for case-insensitive equality with MATLAB-compatible implicit expansion.

strcmpi(a, b) compares text values without considering case and returns logical results element-wise. It supports MATLAB-compatible string, char, and cellstr-style containers with implicit expansion.

Syntax

tf = strcmpi(A, B)

Inputs

NameTypeRequiredDefaultDescription
AAnyYesFirst text input (string/char/cell/string array).
BAnyYesSecond text input (string/char/cell/string array).

Returns

NameTypeDescription
tfLogicalArrayLogical comparison result.

Errors

IdentifierWhenMessage
RunMat:strcmpi:InvalidInputAt least one input is not a supported text container.strcmpi: text inputs must be string/char/cell/string-array values
RunMat:strcmpi:ShapeMismatchInputs are not broadcast-compatible for elementwise comparison.strcmpi: input sizes are not broadcast-compatible
RunMat:strcmpi:InternalErrorInternal logical result assembly failed.strcmpi: internal error

How strcmpi works

  • Case-insensitive: Letter case is ignored. "RunMat", "runmat", and "RUNMAT" all compare equal.
  • Accepted text types: Works with string arrays, character vectors or matrices, and cell arrays of character vectors. Mixed combinations are normalised automatically.
  • Implicit expansion: Scalar operands expand against array operands so element-wise comparisons follow MATLAB broadcasting rules.
  • Character arrays: Rows are compared individually. Results are column vectors whose length equals the number of rows in the character array.
  • Cell arrays: Each cell is treated as a text scalar. Scalar cells expand across the other operand before comparison.
  • Missing strings: Elements whose value is missing ("<missing>") always compare unequal, even to other missing values, matching MATLAB.
  • Result form: Scalar comparisons return logical scalars. Otherwise the result is a logical array that matches the broadcast shape.

Does RunMat run strcmpi on the GPU?

strcmpi is registered as an acceleration sink. When either operand resides on the GPU, RunMat gathers both to host memory before comparing them. This keeps behaviour identical to MATLAB and avoids requiring backend-specific kernels. The logical result is produced on the CPU and never remains GPU-resident.

GPU memory and residency

You rarely need to call gpuArray manually. When inputs already live on the GPU, RunMat gathers them before calling strcmpi, then returns a logical result on the host. This matches MATLAB’s behaviour while keeping the runtime simple. Subsequent GPU-aware code can explicitly transfer results back if needed.

Examples

Compare Two Strings Ignoring Case

tf = strcmpi("RunMat", "runmat")

Expected output:

tf = logical
   1

Find Case-Insensitive Matches Inside a String Array

colors = ["Red" "GREEN" "blue"];
mask = strcmpi(colors, "green")

Expected output:

mask = 1×3 logical array
   0   1   0

Compare Character Array Rows Without Case Sensitivity

animals = char("Cat", "DOG", "cat");
tf = strcmpi(animals, "cAt")

Expected output:

tf = 3×1 logical array
   1
   0
   1

Compare Cell Arrays Of Character Vectors Case-Insensitively

C1 = {'north', 'East', 'SOUTH'};
C2 = {'NORTH', 'east', 'west'};
tf = strcmpi(C1, C2)

Expected output:

tf = 1×3 logical array
   1   1   0

Broadcast A String Scalar Against A Character Matrix

patterns = char("alpha", "BETA");
tf = strcmpi(patterns, ["ALPHA" "beta"])

Expected output:

tf = 2×2 logical array
   1   0
   0   1

Handle Missing Strings In Case-Insensitive Comparisons

values = ["Active" missing];
mask = strcmpi(values, "active")

Expected output:

mask = 1×2 logical array
   1   0

Using strcmpi with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how strcmpi changes the result.

Run a small strcmpi example, explain the result, then change one input and compare the output.

FAQ

Does strcmpi support string arrays, character arrays, and cell arrays?

Yes. All MATLAB-supported text containers are accepted, and mixed combinations are handled automatically with implicit expansion.

Is whitespace significant when comparing character arrays?

Yes. Trailing spaces or different lengths make rows unequal, just like strcmp. Use strtrim or strip if you need to ignore whitespace.

Do missing strings compare equal?

No. The missing sentinel compares unequal to all values, including another missing string scalar.

Can I compare complex numbers or numeric arrays with strcmpi?

No. Both arguments must contain text. Numeric inputs produce a descriptive MATLAB-style error.

How are GPU inputs handled?

They are gathered to the CPU automatically before comparison. Providers do not need to implement additional kernels for strcmpi.

What is returned when both inputs are scalars?

A logical scalar is returned (true or false). For non-scalar shapes, a logical array that mirrors the broadcast dimensions is produced.

What is strcmpi in MATLAB?

strcmpi(s1, s2) compares two text values for equality while ignoring letter case. It returns true when the strings match case-insensitively and false otherwise. The i stands for *insensitive*. Use strcmp when you do want case to matter, and strncmpi when you only want to compare the first n characters.

How does strcmpi behave with cell arrays or string arrays?

— When one operand is a cell array or string array and the other is a scalar, strcmpi broadcasts the scalar elementwise and returns a logical array of the same shape. For example:

strcmpi({'apple','Banana','CHERRY'}, 'banana')
% ans =  1x3 logical array
%   0   1   0

When both operands are arrays of the same shape, they are compared element-by-element. This matches MATLAB's implicit-expansion rules.

Does strcmpi work across mixed char/string inputs?

— Yes. Character vectors ('Hello'), string scalars ("Hello"), and cells of character vectors all interoperate, so strcmpi('hello', "Hello") returns true. Note that strcmpi only tests exact equality (ignoring case). For case-insensitive *substring* matching, use contains(str, pattern, 'IgnoreCase', true) or regexpi.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how strcmpi is executed, line by line, in Rust.

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.