RunMat
GitHub

strcmp — Compare text inputs for exact case-sensitive equality with MATLAB-compatible implicit expansion.

strcmp(a, b) returns logical true when corresponding text values match exactly and false otherwise. It supports MATLAB-compatible string, char, and cellstr-style inputs with implicit expansion.

Syntax

tf = strcmp(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:strcmp:InvalidInputAt least one input is not a supported text container.strcmp: text inputs must be string/char/cell/string-array values
RunMat:strcmp:ShapeMismatchInputs are not broadcast-compatible for elementwise comparison.strcmp: input sizes are not broadcast-compatible
RunMat:strcmp:InternalErrorInternal logical result assembly failed.strcmp: internal error

How strcmp works

  • Accepted text types: Works with string scalars/arrays, character vectors or matrices created with char, and cell arrays of character vectors. Mixed combinations are converted automatically, matching MATLAB.
  • Implicit expansion: Scalar inputs expand to the shape of the other operand, producing element-wise comparisons for higher-dimensional arrays.
  • Character arrays: Rows are compared individually. The result is a column vector whose length equals the number of rows in the character array.
  • Cell arrays: Each cell is treated as a text scalar. Scalar cell arrays expand across the other operand before comparison.
  • Missing strings: String elements equal to missing compare unequal to everything, including other missing values.
  • Result form: A single logical scalar is returned for scalar comparisons; otherwise you receive a logical array using column-major MATLAB layout.
  • Case sensitivity: Matching is case-sensitive. Use strcmpi for case-insensitive comparisons.

Does RunMat run strcmp on the GPU?

strcmp is registered as an acceleration sink. When either input resides on the GPU, RunMat gathers both operands back to host memory before comparing them so the results match MATLAB exactly. Providers do not need to implement custom kernels, and the logical result is always returned on the CPU.

GPU memory and residency

You normally do not need to call gpuArray. If you do, RunMat gathers the operands before computing strcmp so the output matches MATLAB. The result always lives on the host because this builtin inspects text data.

Examples

Compare Two Equal Strings

tf = strcmp("RunMat", "RunMat")

Expected output:

tf = logical
   1

Compare String Array With Scalar Text

names = ["red" "green" "blue"];
tf = strcmp(names, "green")

Expected output:

tf = 1×3 logical array
   0   1   0

Compare Character Array Rows

labels = char("cat", "dog", "cat");
tf = strcmp(labels, "cat")

Expected output:

tf = 3×1 logical array
   1
   0
   1

Compare Two Cell Arrays Of Character Vectors

C1 = {'apple', 'pear', 'grape'};
C2 = {'apple', 'peach', 'grape'};
tf = strcmp(C1, C2)

Expected output:

tf = 1×3 logical array
   1   0   1

Handle Missing Strings

vals = ["alpha" missing];
tf = strcmp(vals, "alpha")

Expected output:

tf = 1×2 logical array
   1   0

Implicit Expansion With Column Vector Text

patterns = char("north", "south");
tf = strcmp(patterns, ["north" "east"])

Expected output:

tf = 2×2 logical array
   1   0
   0   0

Using strcmp with coding agents

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

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

FAQ

What types can I pass to strcmp?

Use string arrays, character vectors/arrays, or cell arrays of character vectors. Mixed combinations are accepted and follow MATLAB's implicit expansion rules.

Does strcmp ignore letter case?

No. strcmp is case-sensitive. Use strcmpi for case-insensitive comparisons.

What happens when the inputs contain missing strings?

Missing string scalars compare unequal to every value (including other missing strings), so the result is false.

Can strcmp compare matrices of characters?

Yes. Character arrays compare row-by-row, returning a column vector whose entries tell you whether each row matches.

Does strcmp return numeric or logical results?

It returns logical results. Scalars become logical scalars (Value::Bool), while arrays are returned as logical arrays.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how strcmp 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.