join — Combine text across a specified dimension inserting delimiters between elements.
join concatenates text along a chosen dimension of a string array or a cell array of character vectors. It inserts delimiters between neighbouring elements and mirrors MATLAB semantics for default dimension selection, delimiter broadcasting, and handling of missing strings.
How join works in RunMat
- When you omit the dimension,
joinoperates along the **last dimension whose size is not 1**. If all dimensions are singleton, it uses dimension 2. - The default delimiter is a single space character. You can pass a scalar delimiter (string or character vector) or supply a string/cell array whose shape matches the input, with the join dimension reduced by one, to customise delimiters for each gap.
- Inputs may be string scalars, string arrays (including N-D), character arrays, or cell arrays of character vectors. Cell inputs return cell arrays; all other inputs return string scalars or string arrays.
- If any element participating in a join is the string
<missing>, the result for that slice is also<missing>, matching MATLAB’s missing propagation rules. - Joining along a dimension greater than
ndims(str)leaves the input unchanged.
How join runs on the GPU
join executes on the CPU. When text or delimiters reside on the GPU, RunMat gathers them to host memory before performing the concatenation, ensuring identical results to MATLAB. Providers do not need to implement custom kernels for this builtin today.
GPU memory and residency
No. Text manipulation currently runs on the CPU. If your text or delimiters were produced on the GPU, RunMat gathers them automatically so that you can call join without extra steps.
Examples
Combine Strings In Each Row Of A Matrix
names = ["Carlos" "Sada"; "Ella" "Olsen"; "Diana" "Lee"];
fullNames = join(names)Expected output:
fullNames = 3×1 string
"Carlos Sada"
"Ella Olsen"
"Diana Lee"Insert A Custom Delimiter Between Elements
labels = ["x" "y" "z"; "a" "b" "c"];
joined = join(labels, "-")Expected output:
joined = 2×1 string
"x-y-z"
"a-b-c"Provide A Delimiter Array That Varies Per Row
str = ["x" "y" "z"; "a" "b" "c"];
delims = [" + " " = "; " - " " = "];
equations = join(str, delims)Expected output:
equations = 2×1 string
"x + y = z"
"a - b = c"Join Along A Specific Dimension
scores = ["Alice" "Bob"; "92" "88"; "85" "90"];
byColumn = join(scores, 1)Expected output:
byColumn = 1×2 string
"Alice 92 85" "Bob 88 90"Join A Cell Array Of Character Vectors
C = {'GPU', 'Accelerate'; 'Ignition', 'Interpreter'};
result = join(C, ", ")Expected output:
result = 2×1 cell
{'GPU, Accelerate'}
{'Ignition, Interpreter'}Join Using A Dimension Argument As The Second Input
words = ["RunMat"; "Accelerate"; "Planner"];
sentence = join(words, 1)Expected output:
sentence = "RunMat Accelerate Planner"Join Rows Of An Empty String Array
emptyRows = strings(2, 0);
out = join(emptyRows)Expected output:
out = 2×1 string
""
""FAQ
How does join choose the dimension when I do not specify one?
It looks for the last dimension whose size is not 1 and joins along that axis. If every dimension has size 1, it uses dimension 2.
Can I use different delimiters between separate pairs of strings?
Yes. Supply a string array or a cell array of character vectors with the same size as str, except that the join dimension must be one element shorter. Values of size 1 in other dimensions broadcast.
What happens when str contains <missing>?
The result for that slice becomes <missing>. This matches MATLAB’s behaviour and ensures missing values propagate.
Can I pass GPU-resident text or delimiters?
You can; RunMat gathers them to host memory automatically before performing the join.
What if I request a dimension larger than ndims(str)?
join returns the original text unchanged, matching MATLAB semantics.
Does join support numeric or logical inputs?
No. Convert them to strings first (e.g., with string or compose), then call join.
How do I join every element into a single string?
Specify the dimension explicitly. For column vectors, use join(str, 1); for higher dimensional arrays, choose the axis that spans the elements you want to combine.
Are cell array outputs returned as strings?
No. When the input is a cell array, the output is a cell array of character vectors, keeping parity with MATLAB.
Related functions to explore
These functions work well alongside join. Each page has runnable examples you can try in the browser.
split, compose, string, erase, eraseBetween, extractBetween, lower, pad, replace, strcat, strip, strrep, strtrim, upper
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how join works, line by line, in Rust.
- View join.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.