strcat — Concatenate text inputs element-wise with MATLAB-compatible trimming and implicit expansion.
strcat horizontally concatenates text inputs element-wise. It accepts string arrays, character arrays, character vectors, and cell arrays of character vectors, applying MATLAB's implicit expansion rules to match array sizes.
How strcat works in RunMat
- Inputs are concatenated element-wise. Scalars expand across arrays of matching dimensions using MATLAB's implicit expansion rules.
- When at least one input is a string array (or string scalar), the result is a string array.
<missing>values propagate, so any missing operand yields a missing result for that element. - When no string arrays are present but any input is a cell array of character vectors, the result is a cell array whose elements are character vectors.
- Otherwise, the result is a character array. For character inputs,
strcatremoves trailing space characters from each operand **before** concatenating. - Cell array elements must be character vectors (or string scalars). Mixing cell arrays with unsupported content raises a MATLAB-compatible error.
- Empty inputs broadcast naturally: an operand with a zero-length dimension yields an empty output after broadcasting.
How strcat runs on the GPU
RunMat currently performs text concatenation on the CPU. When any operand resides on the GPU, the runtime gathers it to host memory before applying MATLAB-compatible trimming and concatenation rules. Providers do not need to implement device kernels for this builtin today.
GPU memory and residency
No. String manipulation runs on the CPU. If intermediate values are on the GPU, RunMat gathers them automatically so you can call strcat without extra residency management.
Examples
Concatenate string scalars element-wise
greeting = strcat("Run", "Mat")Expected output:
greeting = "RunMat"Concatenate a string scalar with a string array
names = ["Ignition", "Turbine", "Accelerate"];
tagged = strcat("runmat-", names)Expected output:
tagged = 1×3 string
"runmat-Ignition" "runmat-Turbine" "runmat-Accelerate"Concatenate character arrays while trimming trailing spaces
A = char("GPU ", "Planner");
B = char("Accel", " Stage ");
result = strcat(A, B)Expected output:
result =
2×11 char array
'GPUAccel'
'PlannerStage'Concatenate cell arrays of character vectors
C = {'Run ', 'Plan '; 'Fuse ', 'Cache '};
suffix = {'Mat', 'Ops'; 'Kernels', 'Stats'};
combined = strcat(C, suffix)Expected output:
combined = 2×2 cell
{'RunMat'} {'PlanOps'}
{'FuseKernels'} {'CacheStats'}Propagate missing strings during concatenation
values = [string(missing) "ready"];
out = strcat("job-", values)Expected output:
out = 1×2 string
<missing> "job-ready"Broadcast a scalar character vector across a character array
labels = char("core", "runtime", "planner");
prefixed = strcat("runmat-", labels)Expected output:
prefixed =
3×11 char array
'runmat-core'
'runmat-runtime'
'runmat-planner'FAQ
Does strcat remove spaces between words?
No. strcat only strips trailing **space characters** from character inputs before concatenating. Spaces in the middle of a string remain untouched. To insert separators explicitly, concatenate the desired delimiter or use join.
How are missing strings handled?
Missing string scalars (string(missing)) propagate. If any operand is missing for a specific element, the resulting element is <missing>.
What happens when I mix strings and character arrays?
The output is a string array. Character inputs are converted to strings (after trimming trailing spaces) and combined element-wise with the string operands.
Can I concatenate cell arrays with string arrays?
Yes. Inputs are implicitly converted to strings when any operand is a string array, so the result is a string array. Cell array elements must still contain character vectors (or scalar strings).
What if I pass numeric or logical inputs?
strcat only accepts strings, character arrays, character vectors, or cell arrays of character vectors. Passing unsupported types raises a MATLAB-compatible error.
How are empty inputs treated?
Dimensions with length zero propagate through implicit expansion. For example, concatenating with an empty string array returns an empty array with the broadcasted shape.
Related functions to explore
These functions work well alongside strcat. Each page has runnable examples you can try in the browser.
string, plus, join, cellstr, erase, eraseBetween, extractBetween, lower, pad, replace, split, strip, strrep, strtrim, upper
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how strcat works, line by line, in Rust.
- View strcat.rs on GitHub
- Learn how the 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 — faster, on any GPU, with no license required.
- Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
- Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
- A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.