strcmp — Compare text inputs for exact case-sensitive equality with implicit expansion.
strcmp(A, B) compares text elementwise, preserving text-container broadcasting and returning logical results.
Syntax
tf = strcmp(A, B)Inputs
A- Type
Any- Required
- Yes
- Description
- First string, character array, or cellstr operand.
B- Type
Any- Required
- Yes
- Description
- Second string, character array, or cellstr operand.
Returns
tf- Type
LogicalArray- Description
- Logical comparison result.
Errors
RunMat:strcmp:InvalidInput- When
- At least one input is not a supported text container.
- Message
strcmp: text inputs must be string/char/cell/string-array values
RunMat:strcmp:ShapeMismatch- When
- Inputs are not broadcast-compatible for elementwise comparison.
- Message
strcmp: input sizes are not broadcast-compatible
RunMat:strcmp:InternalError- When
- Internal logical result assembly failed.
- Message
strcmp: internal error
RunMat:strcmp:TooManyOutputs- When
- More than one output is requested.
- Message
strcmp: too many output arguments
Behavior
strcmp(A, B) compares text exactly and returns a logical scalar or array. It accepts string scalars and arrays, character vectors and matrices, and cell arrays of character vectors.
Each character-array row is one text element. Character matrices therefore produce column-shaped comparison results; scalar operands expand against compatible text arrays, including N-D string arrays.
Missing string elements compare false, even against another missing element. Comparison is case-sensitive; use strcmpi to ignore letter case.
Direct integer, numeric, symbolic, logical, and provider-resident operands are unsupported text and return scalar logical false before provider access or validation of the other operand. When neither operand takes that direct-false route, malformed host cell elements report an input error rather than being silently converted.
Placement and effects
The default binding compares text on the host in native and browser runtimes. It has no GPU text kernel or fusion form. It may throw for invalid text containers or incompatible shapes, but has no callback, workspace, filesystem, randomness, network, or time effects.
An unused output is evaluated and discarded; more than one output is invalid. Text comparison does not create or mutate device allocations. Ordinary distribution of host text values is separate from distributed-input support for this builtin.
Examples
Compare equal string scalars
tf = strcmp("RunMat", "RunMat")Expected output:
tf = logical 1Compare a string array with a scalar
names = ["red" "green" "blue"]; tf = strcmp(names, "green")Expected output:
tf = [false true false]Compare character-array rows
labels = char("cat", "dog", "cat"); tf = strcmp(labels, "cat")Expected output:
tf = [true; false; true]Compare cell arrays
C1 = {'apple', 'pear', 'grape'}; C2 = {'apple', 'peach', 'grape'}; tf = strcmp(C1, C2)Expected output:
tf = [true false true]Missing strings compare unequal
vals = ["alpha" missing]; tf = strcmp(vals, "alpha")Expected output:
tf = [true false]Expand a character matrix against a string row
patterns = char("north", "south"); tf = strcmp(patterns, ["north" "east"])Expected output:
tf = [true false; false false]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?⌄
String arrays, character vectors or matrices, and cell arrays of character vectors. Compatible scalar operands expand against array operands.
Does strcmp ignore letter case?⌄
No. Use strcmpi for case-insensitive comparison.
What happens when an input contains missing strings?⌄
A missing string compares unequal to every text element, including another missing string.
Can strcmp compare character matrices?⌄
Yes. It compares rows as text elements and returns a column-shaped logical result.
Is the result numeric or logical?⌄
It is logical. Scalar comparisons return a logical scalar; array comparisons return a logical array.
Related Strings functions
Core
blanks · char · compose · convertCharsToStrings · convertContainedStringsToChars · convertStringsToChars · genvarname · int2str · isletter · isspace · isStringScalar · isstrprop · mat2str · native2unicode · newline · num2str · sprintf · sscanf · str2double · str2num · strcmpi · 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
Source you can read
Every RunMat function's source is public. Read exactly how strcmp is executed, line by line, in Rust.
- View the source for strcmp in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.