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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
A | Any | Yes | — | First text input (string/char/cell/string array). |
B | Any | Yes | — | Second text input (string/char/cell/string array). |
Returns
| Name | Type | Description |
|---|---|---|
tf | LogicalArray | Logical comparison result. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:strcmpi:InvalidInput | At least one input is not a supported text container. | strcmpi: text inputs must be string/char/cell/string-array values |
RunMat:strcmpi:ShapeMismatch | Inputs are not broadcast-compatible for elementwise comparison. | strcmpi: input sizes are not broadcast-compatible |
RunMat:strcmpi:InternalError | Internal 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.
- Unsupported datatypes: Integer and other unsupported numeric inputs return scalar logical
false; they are neither gathered nor converted to strings.
Does RunMat run strcmpi on the GPU?
strcmpi is a host text comparison sink. Numeric resident operands are unsupported datatypes and return scalar logical false without gather or backend-specific kernels.
GPU memory and residency
strcmpi compares host text and returns host logical output. Unsupported numeric resident operands return false without provider access.
Examples
Compare Two Strings Ignoring Case
tf = strcmpi("RunMat", "runmat")Expected output:
tf = logical
1Find Case-Insensitive Matches Inside a String Array
colors = ["Red" "GREEN" "blue"];
mask = strcmpi(colors, "green")Expected output:
mask = 1×3 logical array
0 1 0Compare Character Array Rows Without Case Sensitivity
animals = char("Cat", "DOG", "cat");
tf = strcmpi(animals, "cAt")Expected output:
tf = 3×1 logical array
1
0
1Compare 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 0Broadcast 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 1Handle Missing Strings In Case-Insensitive Comparisons
values = ["Active" missing];
mask = strcmpi(values, "active")Expected output:
mask = 1×2 logical array
1 0Using 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?⌄
Numeric values are unsupported text operands. Following the documented comparison rule, strcmpi returns scalar logical false rather than converting them to text.
How are GPU inputs handled?⌄
RunMat has no GPU text representation. A provider-resident numeric value is an unsupported text operand, so strcmpi returns scalar logical false without gathering it or accessing the provider.
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 0When 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.
Related Strings functions
Core
blanks · char · compose · convertCharsToStrings · convertContainedStringsToChars · convertStringsToChars · genvarname · int2str · isletter · isspace · isStringScalar · isstrprop · mat2str · native2unicode · newline · num2str · sprintf · sscanf · str2double · str2num · strcmp · string · string.empty · strings · strlength · strncmp · strncmpi · strtok · unicode2native
Text Analytics
addDependencyDetails · addEntityDetails · addLemmaDetails · addPartOfSpeechDetails · addSentenceDetails · addTypeDetails · bagOfNgrams · bagOfWords · cosineSimilarity · doc2sequence · encode · extractFileText · extractHTMLText · fastTextWordEmbedding · findElement · getAttribute · htmlTree · ind2word · isVocabularyWord · normalizeWords · readWordEmbedding · removeLongWords · removeShortWords · removeStopWords · removeWords · stopWords · tokenDetails · tokenizedDocument · trainWordEmbedding · vaderSentimentScores · vec2word · word2ind · word2vec · wordEncoding · writeWordEmbedding
Transform
append · deblank · erase · eraseBetween · erasePunctuation · eraseURLs · extractAfter · extractBefore · extractBetween · insertAfter · insertBefore · join · lower · pad · replace · replaceBetween · reverse · split · splitlines · strcat · strip · strjoin · strjust · strrep · strsplit · strtrim · upper
Search
contains · endsWith · matches · startsWith · strfind
Pattern
digitsPattern · lettersPattern · pattern · regexpPattern · textBoundary · wildcardPattern
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how strcmpi is executed, line by line, in Rust.
- View the source for strcmpi 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.