RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.2, Nov 26, 2026 ·

RunMat® is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
See all docs
Builtin Reference
    • blanks
    • char
    • compose
    • convertCharsToStrings
    • convertContainedStringsToChars
    • convertStringsToChars
    • genvarname
    • int2str
    • isletter
    • isspace
    • isStringScalar
    • isstrprop
    • mat2str
    • native2unicode
    • newline
    • num2str
    • sprintf
    • sscanf
    • str2double
    • str2num
    • strcmp
    • strcmpi
    • string
    • string.empty
    • strings
    • strlength
    • strncmp
    • strncmpi
    • strtok
    • unicode2native

strncmp — Compare up to N leading characters of text, case-sensitively.

strncmp(A, B, N) returns logical prefix-comparison results with compatible text-container expansion.

Syntax

tf = strncmp(A, B, N)

Inputs

A
Type
Any
Required
Yes
Description
First text operand.
B
Type
Any
Required
Yes
Description
Second text operand.
N
Type
IntegerScalar
Required
Yes
Description
Maximum number of leading characters to compare.
NameTypeRequiredDefaultDescription
AAnyYes—First text operand.
BAnyYes—Second text operand.
NIntegerScalarYes—Maximum number of leading characters to compare.

Returns

tf
Type
LogicalArray
Description
Logical prefix-comparison result.
NameTypeDescription
tfLogicalArrayLogical prefix-comparison result.

Errors

RunMat:strncmp:InvalidInput
When
At least one text input is not a supported text container.
Message
strncmp: text inputs must be string/char/cell/string-array values
RunMat:strncmp:ShapeMismatch
When
Text inputs are not broadcast-compatible.
Message
strncmp: input sizes are not broadcast-compatible
RunMat:strncmp:InvalidPrefixLength
When
Prefix length is not a finite integral scalar representable as a host count.
Message
strncmp: prefix length must be a finite nonnegative integer scalar
IdentifierWhenMessage
RunMat:strncmp:InvalidInputAt least one text input is not a supported text container.strncmp: text inputs must be string/char/cell/string-array values
RunMat:strncmp:ShapeMismatchText inputs are not broadcast-compatible.strncmp: input sizes are not broadcast-compatible
RunMat:strncmp:InvalidPrefixLengthPrefix length is not a finite integral scalar representable as a host count.strncmp: prefix length must be a finite nonnegative integer scalar
RunMat:strncmp:InternalErrorInternal logical result assembly failed.strncmp: internal error
RunMat:strncmp:TooManyOutputsMore than one output is requested.strncmp: too many output arguments

Behavior

strncmp(A, B, N) compares at most N leading Unicode scalar values from each corresponding text element, case-sensitively. It accepts string scalars and arrays, character vectors and matrices, and cell arrays of character vectors. Scalar text expands against compatible arrays; character-matrix rows are independent text elements.

N accepts real scalar double, single, logical, and all eight fixed-width integer classes. Native integer storage is read exactly. A negative integral N is treated as zero; zero makes every element comparison true, including missing strings. Unrepresentable host counts and nonintegral or nonfinite floating values reject; a floating count is not rounded to a nearby integer.

For positive N, missing string elements compare false. If both text elements end before N and all compared characters matched, the result is true; an extra character on either side before N makes it false.

Unsupported direct numeric or provider-resident operands in A or B return scalar logical false before N parsing or provider access. N may be a supported resident scalar and is gathered before exact validation; no string comparison runs on a GPU.

Placement and effects

This default binding performs host text comparison in native and browser runtimes. Gathering a supported resident N may suspend before host validation; there is no GPU text kernel or fusion form. It has no callback, workspace, filesystem, randomness, network, or time effects. Invalid N or incompatible text shape can throw.

Zero requested outputs evaluates and discards the result; more than one output is invalid. Ordinary worker transfer of host text is separate from unsupported distributed-input execution.

Examples

Compare leading characters

tf = strncmp("RunMat", "Runway", 3)

Expected output:

tf = logical 1

Expand a prefix across strings

names = ["north" "south" "east"]; tf = strncmp(names, "no", 2)

Expected output:

tf = [true false false]

Compare rows of a character matrix

animals = char("cat", "camel", "cow"); tf = strncmp(animals, "ca", 2)

Expected output:

tf = [true; true; false]

Compare cell arrays

C1 = {'red', 'green', 'blue'}; C2 = {'rose', 'grey', 'black'}; tf = strncmp(C1, C2, 2)

Expected output:

tf = [false true true]

A zero-length comparison succeeds

tf = strncmp("alpha", "omega", 0)

Expected output:

tf = logical 1

Use an exact integer prefix count

tf = strncmp("RunMat", "Runway", uint64(3))

Expected output:

tf = logical 1

Using strncmp with coding agents

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

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

FAQ

What types can I pass to strncmp?⌄

A and B accept string arrays, character vectors or matrices, and cell arrays of character vectors. N accepts real integral scalar double, single, or fixed-width integer; negative values act as zero.

Is comparison case-sensitive?⌄

Yes. Use strncmpi to ignore letter case.

What if N is zero?⌄

Every element comparison is true because no characters are compared.

What if a string ends before N?⌄

It compares equal only if the other string also ends at that point after the same characters.

How are missing strings treated?⌄

For positive N, any comparison involving a missing string is false. For zero N, every comparison is true.

What is the result class?⌄

Logical; scalar inputs yield a logical scalar and expanded inputs yield a logical array in column-major order.

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 · strcmpi · string · string.empty · strings · strlength · 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

Regex

regexp · regexpi · regexprep

Source you can read

Every RunMat function's source is public. Read exactly how strncmp is executed, line by line, in Rust.

  • View the source for strncmp 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.

Getting started · Benchmarks · Pricing

Download RunMat

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

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • Behavior
  • Placement and effects
  • Examples
  • Compare leading characters
  • Expand a prefix across strings
  • Compare rows of a character matrix
  • Compare cell arrays
  • A zero-length comparison succeeds
  • Use an exact integer prefix count
  • Using strncmp with coding agents
  • FAQ
  • Related Strings functions
  • Core
  • Text Analytics
  • Transform
  • Search
  • Pattern
  • Regex
  • Source you can read
  • About RunMat