RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

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.

LicensePrivacy
/
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

strlength — Return per-element character counts for text inputs with MATLAB-compatible output shaping.

strlength(str) counts characters in each text element across string, char, and cellstr-style inputs. It returns MATLAB-compatible double arrays shaped to match elementwise input structure.

Syntax

L = strlength(str)

Inputs

NameTypeRequiredDefaultDescription
strAnyYes—String array, character array, or cell array of text scalars.

Returns

NameTypeDescription
LNumericArrayCharacter counts for each text element.

Errors

IdentifierWhenMessage
RunMat:strlength:InvalidInputInput is not a string array, character array, or cell array of text scalars.strlength: first argument must be a string array, character array, or cell array of character vectors
RunMat:strlength:InvalidCellElementA cell-array element is not a character row vector or scalar string.strlength: cell array elements must be character vectors or string scalars
RunMat:strlength:InternalErrorInternal tensor construction failed while building length results.strlength: internal error

How strlength works

  • String arrays return a numeric array of the same size; string scalars yield a scalar double.
  • Character arrays report the number of characters per row and ignore padding that MATLAB inserts to keep rows the same width.
  • Character vectors stored in cells contribute one scalar per cell element; the output array matches the cell array shape.
  • Missing string scalars (for example values created with string(missing)) yield NaN. RunMat displays these entries as <missing> in the console just like MATLAB.
  • Empty text inputs produce zeros-sized numeric outputs that match MATLAB's dimension rules.
  • Integer arrays are not interpreted as character codes. Use string first if the intended operation is to count characters in formatted numbers.

Does RunMat run strlength on the GPU?

strlength executes on host text and requires no provider kernel. A numeric or provider-resident value is not a text container and rejects before provider access.

Examples

Measure Characters In A String Scalar

len = strlength("RunMat")

Expected output:

len = 6

Count Characters Across A String Array

labels = ["North" "South" "East" "West"];
counts = strlength(labels)

Expected output:

counts = 1×4
    5    5    4    4

Compute Lengths For Each Row Of A Character Array

names = char("cat", "giraffe");
row_counts = strlength(names)

Expected output:

row_counts = 2×1
     3
     7

Handle Empty And Blank Strings

mixed = ["", "   "];
len = strlength(mixed)

Expected output:

len = 1×2
     0     3

Get Lengths From A Cell Array Of Character Vectors

C = {'red', 'green', 'blue'};
L = strlength(C)

Expected output:

L = 1×3
     3     5     4

Treat Missing Strings As NaN

values = string(["alpha" "beta" "gamma"]);
values(2) = string(missing);  % Displays as <missing> when printed
lengths = strlength(values)

Expected output:

lengths = 1×3
    5   NaN    5

Using strlength with coding agents

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

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

FAQ

What numeric type does strlength return?⌄

strlength always returns doubles, even when all lengths are whole numbers. MATLAB uses doubles for most numeric results, and RunMat follows the same rule.

Why are padded spaces in character arrays ignored?⌄

When MATLAB builds a character array from rows of different lengths, it pads shorter rows with spaces. Those padding characters are not part of the logical content, so strlength removes them before counting. Explicit trailing spaces that you type in a single character vector remain part of the count.

How are missing string values handled?⌄

Missing string scalars display as <missing> and produce NaN lengths. Use ismissing or fillmissing if you need to substitute a default length.

Can I call strlength with numeric data?⌄

No. strlength only accepts string arrays, character vectors/arrays, or cell arrays of character vectors. Numeric inputs raise an error—use num2str first if you need to convert numbers to text.

Does strlength support multibyte Unicode characters?⌄

Yes. Each Unicode scalar value counts as one character, so emoji or accented letters contribute a length of one. Surrogate pairs are treated as a single character, matching MATLAB's behaviour.

Will strlength ever execute on the GPU?⌄

No. RunMat has no GPU text representation, and strlength operates on host text. A provider-resident numeric value is not text and rejects before RunMat accesses or gathers it.

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 · 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

Regex

regexp · regexpi · regexprep

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how strlength is executed, line by line, in Rust.

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

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
  • How strlength works
  • Does RunMat run strlength on the GPU?
  • Examples
  • Measure Characters In A String Scalar
  • Count Characters Across A String Array
  • Compute Lengths For Each Row Of A Character Array
  • Handle Empty And Blank Strings
  • Get Lengths From A Cell Array Of Character Vectors
  • Treat Missing Strings As NaN
  • Using strlength with coding agents
  • FAQ
  • Related Strings functions
  • Core
  • Text Analytics
  • Transform
  • Search
  • Pattern
  • Regex
  • Open-source implementation
  • About RunMat