RunMat
GitHub

strcmpi — Compare text inputs for equality without considering letter case, matching MATLAB's strcmpi semantics.

strcmpi(a, b) compares text values without considering letter case. It returns logical true when inputs match case-insensitively and false otherwise. Supported text types mirror MATLAB: string scalars/arrays, character vectors and arrays, and cell arrays filled with character vectors.

Syntax

tf = strcmpi(s1, s2)
  • s1 and s2 are the text values to compare. Accepted types: character vector ('abc'), character matrix (char(...)), string scalar or array ("abc", ["a" "b"]), or cell array of character vectors ({'a','b'}). Types can be mixed — strcmpi('hello', "Hello") returns true.
  • When one operand is a scalar (a single string or 1×1 cell/string) and the other is an array/cell of strings, MATLAB broadcasts the scalar elementwise across the array. For same-shape arrays, comparison is elementwise.
  • Returns tf, a logical scalar when both inputs are scalars, or a logical array whose shape matches the broadcast result. missing string values always compare unequal, mirroring MATLAB.
  • For exact (case-sensitive) equality use strcmp. For case-insensitive *substring* matching (rather than full equality), use contains(s, pattern, 'IgnoreCase', true) or regexpi.

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.

How RunMat runs 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

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 works, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code — faster, on any GPU, with no license required.

  • Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
  • Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
  • A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.

Getting started · Benchmarks · Pricing

Try RunMat for free

Write code or describe what you want to compute. The sandbox is free, no account required.