RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.1, Nov 17, 2026

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.

/
See all docs
Builtin Reference
    • blkdiag
    • cat
    • circshift
    • diag
    • flip
    • fliplr
    • flipud
    • horzcat
    • ipermute
    • kron
    • permute
    • repelem
    • repmat
    • reshape
    • rot90
    • shiftdim
    • squeeze
    • toeplitz
    • tril
    • triu
    • vertcat

horzcat — Concatenate arrays horizontally in MATLAB and RunMat.

horzcat(A1, A2, ...) concatenates inputs along dimension 2, matching MATLAB square-bracket syntax [A1 A2 ...]. Size compatibility and type coercion follow MATLAB semantics.

Syntax

B = horzcat()
B = horzcat(A1, An...)

Inputs

A1
Type
Any
Required
Yes
Description
First input array.
An
Type
Any
Required
Variadic
Description
Additional input arrays.
NameTypeRequiredDefaultDescription
A1AnyYes—First input array.
AnAnyVariadic—Additional input arrays.

Returns

B
Type
Any
Description
Concatenated array, retaining its class and provider placement where supported.
NameTypeDescription
BAnyConcatenated array, retaining its class and provider placement where supported.

Errors

RunMat:horzcat:InvalidInput
When
Inputs are malformed or incompatible for horizontal concatenation.
Message
horzcat: invalid input arguments
RunMat:horzcat:TypeMismatch
When
Input classes cannot be concatenated together.
Message
horzcat: incompatible input classes for concatenation
IdentifierWhenMessage
RunMat:horzcat:InvalidInputInputs are malformed or incompatible for horizontal concatenation.horzcat: invalid input arguments
RunMat:horzcat:TypeMismatchInput classes cannot be concatenated together.horzcat: incompatible input classes for concatenation

Behavior

Operates on numeric, logical, complex, character, string, and cell arrays with MATLAB-compatible type checking.

All inputs must have the same number of rows (dimension 1). Higher dimensions are padded with singleton sizes where necessary.

Scalars act as 1×1 building blocks, so horzcat(1, 2, 3) produces the row vector [1 2 3].

Empty inputs participate naturally. With no operands, the result is the canonical 0×0 double; nonzero all-empty operands retain compatible geometry and the applicable input class.

When the trailing 'like', prototype pair is supplied, the output matches the prototype's residency (host or GPU) and numeric category.

Compatible mixed gpuArray and host numeric operands use exact gather/concatenate/restore fallback; convert explicitly with gpuArray or gather when you need a specific placement.

GPU execution

horzcat delegates to cat(dim = 2, …). 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=2; 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

Numeric, logical, complex, character, string, and cell arrays use MATLAB-compatible class checks. Inputs have matching row counts; higher dimensions are singleton-padded. Scalars are 1-by-1 building blocks. With no operands, the result is the canonical 0-by-0 double; nonzero all-empty operands retain compatible geometry and the applicable input class.

A trailing 'like', prototype pair selects output residency and numeric category. Compatible mixed host and gpuArray numeric operands use the delegated cat fallback; convert explicitly with gpuArray or gather to control placement.

The operation delegates to cat(dim=2). An owning provider with a cat hook executes on device for supported f32/f64 data; otherwise exact values gather to host for concatenation and are restored through that owner. There is no broadcasting, elementwise/reduction fusion, or independent horzcat kernel.

Examples

Concatenating matrices by columns

A = [1 2; 3 4];
B = [10 20; 30 40];
C = horzcat(A, B)

Expected output:

C =
     1     2    10    20
     3     4    30    40

Building a row vector from scalars

row = horzcat(1, 2, 3, 4)

Expected output:

row = [1 2 3 4]

Extending character arrays into words

lhs = ['Run' ; 'GPU'];
rhs = ['Mat' ; 'Fun'];
words = horzcat(lhs, rhs)

Expected output:

words =
    RunMat
    GPUFun

Keeping gpuArray inputs resident on the device

G1 = gpuArray(rand(256, 128));
G2 = gpuArray(rand(256, 64));
wide = horzcat(G1, G2)

Preserving empties when all inputs are empty

emptyBlock = zeros(0, 3);
result = horzcat(emptyBlock, emptyBlock)

Matching an output prototype with the 'like' syntax

proto = gpuArray.zeros(5, 1);
combo = horzcat(ones(5, 1), zeros(5, 1), "like", proto)

Using horzcat with coding agents

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

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

Related Array functions

Shape

blkdiag · cat · circshift · diag · flip · fliplr · flipud · ipermute · kron · permute · repelem · repmat · reshape · rot90 · shiftdim · squeeze · toeplitz · tril · triu · vertcat

Accumulation

accumarray

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

combinations · nchoosek · perms

Binning

discretize

Indexing

find · ind2sub · sub2ind

Grouping

findgroups · groupcounts · grp2idx · splitapply

Introspection

height · iscolumn · isempty · ismatrix · isrow · isscalar · isvector · length · ndims · numel · size · width

Source you can read

Every RunMat function's source is public. Read exactly how horzcat is executed, line by line, in Rust.

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

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
  • Behavior
  • GPU execution
  • Placement and options
  • Examples
  • Concatenating matrices by columns
  • Building a row vector from scalars
  • Extending character arrays into words
  • Keeping gpuArray inputs resident on the device
  • Preserving empties when all inputs are empty
  • Matching an output prototype with the 'like' syntax
  • Using horzcat with coding agents
  • Related Array functions
  • Shape
  • Accumulation
  • Sorting Sets
  • Creation
  • Combinatorics
  • Binning
  • Indexing
  • Grouping
  • Introspection
  • Source you can read
  • About RunMat