vertcat — Concatenate inputs vertically along the first dimension with MATLAB semicolon semantics.
vertcat(A1, A2, ...) stacks inputs top-to-bottom along dimension 1, equivalent to MATLAB semicolon syntax [A1; A2; ...] with compatible shape rules.
Syntax
B = vertcat()
B = vertcat(A1, An...)Inputs
A1- Type
Any- Required
- Yes
- Description
- First input array.
An- Type
Any- Required
- Variadic
- Description
- Additional input arrays.
Returns
B- Type
Any- Description
- Concatenated array, retaining its class and provider placement where supported.
Errors
RunMat:vertcat:InvalidInput- When
- Inputs are malformed or incompatible for vertical concatenation.
- Message
vertcat: invalid input arguments
RunMat:vertcat:TypeMismatch- When
- Input classes cannot be concatenated together.
- Message
vertcat: incompatible input classes for concatenation
Behavior
Hard-codes dim = 1. All inputs must agree on every dimension except the first.
Accepts numeric, logical, complex, character, string, and cell arrays with the same class-dominance rules as cat(...,1). Real integer mixtures preserve the leftmost participating integer class with saturating conversion.
Scalars are treated as 1×1, enabling concise column-building such as vertcat(1, 2, 3).
Empty inputs participate naturally. If any shared dimension is zero, the result is empty with the expected shape.
Compatible host and resident numeric inputs use the owning provider when possible; otherwise RunMat gathers exact values, concatenates on the host, and restores the result when the owner can preserve its class.
GPU execution
vertcat delegates to cat(dim = 1, …). When the owning acceleration provider implements the cat hook for the operands, concatenation runs on the GPU. Otherwise RunMat gathers, concatenates on host, and attempts to upload the result; if upload is unavailable, floating output can remain on host.
Delegates to cat with dim=1; provider execution is used where supported, otherwise exact gather/host assembly and attempted restoration apply.
GPU floating precisions are f32 and f64; there is no broadcasting, elementwise or reduction fusion, and constants may be inlined.
Placement and options
Dimension 1 is concatenated and every other dimension must agree. Numeric, logical, complex, character, string, and cell arrays follow cat class dominance; real integer mixtures retain the leftmost participating integer class with saturating conversion. Scalars are 1-by-1. Empty inputs retain their compatible shape, including zero shared dimensions.
Host and resident numeric inputs use the owning provider's cat hook where supported; otherwise exact values gather, concatenate on host, and restore to the owner where class and explicit placement allow. No broadcasting or elementwise/reduction fusion is declared.
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)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)Using vertcat with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how vertcat changes the result.
Run a small vertcat example, explain the result, then change one input and compare the output.
Related Array functions
Shape
blkdiag · cat · circshift · diag · flip · fliplr · flipud · horzcat · ipermute · kron · permute · repelem · repmat · reshape · rot90 · shiftdim · squeeze · toeplitz · tril · triu
Accumulation
Sorting Sets
argsort · intersect · ismember · ismembertol · issorted · issortedrows · setdiff · setxor · sort · sortrows · union · unique
Creation
colon · createArray · empty · eye · false · full · inf · int16.empty · int32.empty · int64.empty · int8.empty · linspace · logspace · magic · meshgrid · nan · ndgrid · nonzeros · ones · peaks · rand · randi · randn · randperm · range · sparse · spdiags · speye · spones · sprand · true · uint16.empty · uint32.empty · uint64.empty · uint8.empty · zeros
Combinatorics
Binning
Grouping
Source you can read
Every RunMat function's source is public. Read exactly how vertcat is executed, line by line, in Rust.
- View the source for vertcat 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.