vertcat — Stack inputs top-to-bottom (dimension 1) exactly like MATLAB's semicolon syntax.
vertcat(A1, A2, …) vertically concatenates its inputs, matching the behavior of MATLAB's semicolon array construction [A1; A2; …]. It is the standard way to stack matrices, vectors, or higher-dimensional slices on top of each other.
How vertcat works in RunMat
- Hard-codes
dim = 1. All inputs must agree on every dimension except the first. - Accepts numeric, logical, complex, character, string, and cell arrays with MATLAB-compatible type checking. Mixing classes is an error.
- Scalars are treated as
1×1, enabling concise row-building such asvertcat(1, 2, 3). - Empty inputs participate naturally. If any shared dimension is zero, the result is empty with the expected shape.
- The optional trailing
'like', prototypepair forces the output to match the prototype's data residency (CPU vs GPU) and numeric flavour. - Mixing
gpuArrayinputs with host inputs is disallowed. Convert explicitly viagpuArrayorgatherto control residency.
How vertcat runs on the GPU
vertcat delegates to cat(dim = 1, …). When the active acceleration provider implements the cat hook, concatenation happens entirely on the GPU, keeping gpuArray inputs resident and avoiding costly round-trips. Providers that lack this hook trigger a transparent fallback: RunMat gathers the operands to the host, concatenates them with MATLAB semantics, and uploads the result back to the originating device so downstream code still sees a gpuArray. This mirrors MATLAB's explicit GPU workflows while keeping RunMat's auto-offload planner informed.
Examples
Stacking matrices by adding rows
A = [1 2; 3 4];
B = [5 6; 7 8];
C = vertcat(A, B)Expected output:
C =
1 2
3 4
5 6
7 8Building a column vector from scalars
col = vertcat(1, 2, 3, 4)Expected output:
col =
1
2
3
4Combining character arrays into taller text blocks
top = ['RunMat'];
bottom = ['Rocks!'];
banner = vertcat(top, bottom)Joining string arrays into multi-row tables
header = ["Name" "Score"];
rows = ["Alice" "98"; "Bob" "92"];
table = vertcat(header, rows)Preserving logical masks when stacking
mask1 = logical([1 0 1]);
mask2 = logical([0 1 0]);
stacked = vertcat(mask1, mask2)Extending cell arrays downwards
row1 = {1, "low"};
row2 = {2, "high"};
grid = vertcat(row1, row2)Keeping gpuArray inputs resident on the device
G1 = gpuArray(rand(128, 256));
G2 = gpuArray(rand(64, 256));
stacked = vertcat(G1, G2)Requesting GPU output with the 'like' prototype
proto = gpuArray.zeros(1, 3);
result = vertcat([1 2 3], [4 5 6], "like", proto)Working with empty rows without surprises
empty = zeros(0, 3);
combo = vertcat(empty, empty)Stacking complex matrices preserves imaginary parts
z1 = complex([1 2], [3 4]);
z2 = complex([5 6], [7 8]);
joined = vertcat(z1, z2)Related functions to explore
These functions work well alongside vertcat. Each page has runnable examples you can try in the browser.
cat, horzcat, reshape, gpuArray, gather, circshift, diag, flip, fliplr, flipud, ipermute, kron, permute, repmat, rot90, squeeze, tril, triu
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how vertcat works, line by line, in Rust.
- View vertcat.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.