RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

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.

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

cat — Concatenate arrays along a chosen dimension in MATLAB and RunMat.

cat(dim, A1, A2, ...) concatenates arrays along dimension dim, producing a new array whose slices along that dimension come from the inputs. Non-concatenated dimensions must be size-compatible, and ordering follows MATLAB and RunMat column-major semantics.

Syntax

B = cat(dim, A1, A2, An...)
B = cat(dim, A1, A2, An..., "like", prototype)

Inputs

NameTypeRequiredDefaultDescription
dimNumericScalarYes—Concatenation dimension (1-based).
A1AnyYes—First input array.
A2AnyYes—Second input array.
AnAnyVariadic—Additional input arrays.
namePropertyNameYes"like"Name-value key ('like').
prototypeLikePrototypeYes—Prototype that sets output class/device.

Returns

NameTypeDescription
BAnyConcatenated output array.

Errors

IdentifierWhenMessage
RunMat:cat:TooFewInputsFewer than two input arrays are supplied after dim.cat: at least two input arrays are required
RunMat:cat:InvalidDimensiondim is non-numeric, non-integer, or less than one.cat: dimension must be numeric and >= 1
RunMat:cat:GpuErrorA required gpuArray gather, upload, or provider operation fails.cat: gpuArray operation failed
RunMat:cat:TypeMismatchInputs are from incompatible classes for concatenation.cat: incompatible input classes for concatenation
RunMat:cat:InvalidLikePrototypeThe 'like' name-value form is malformed or uses an unsupported prototype.cat: invalid 'like' prototype

How cat works

  • dim is 1-based and must be a positive integer.
  • Valid unlike-class combinations follow concatenation precedence: string dominates real numeric, character, and logical data; character dominates real numeric data but cannot combine with logical; an integer operand makes the leftmost nonempty integer class dominate real floating and logical operands; otherwise single dominates double, and logical is preserved only when every input is logical.
  • Every ordered mixture of the eight real integer classes is accepted. When a nonempty input remains, empty operands are omitted before class selection; otherwise the leftmost integer class determines output class. Other numeric or logical values convert with ordinary rounding and saturation.
  • Dimensions other than dim must match exactly; missing higher dimensions are treated as size 1 automatically.
  • The size along dim becomes the sum of the corresponding sizes from each input.
  • An empty operand is omitted when a nonempty compatible partner remains; compatible all-empty inputs retain the concatenated empty geometry.
  • gpuArray inputs stay on the device when an acceleration provider is registered, and real or complex numeric host inputs may be mixed with resident inputs in the same call. Paired complex-integer data retains its exact component class and owning provider.
  • RunMat compatibility mode adds an optional trailing "like", prototype pair that can request host or GPU output residency; this pair is not part of the pinned public MATLAB syntax.

Does RunMat run cat on the GPU?

When every supported floating input is a gpuArray, RunMat first calls the active provider's AccelProvider::cat hook. Typed integer data, mixed numeric host/device inputs, runtime empty omission, or providers without the hook use an exact fallback: resident operands are gathered without changing class, empty operands are omitted before class selection when a nonempty input remains, all remaining operands are concatenated on the host in original order, and the result is uploaded to the originating provider. This preserves integer class selection and wide values across the backend boundary. RunMat compatibility mode can additionally use the trailing "like" extension to request output residency.

Examples

Concatenating matrices by stacking rows

A = [1 2; 3 4];
B = [5 6; 7 8];
C = cat(1, A, B)

Expected output:

C =
     1     2
     3     4
     5     6
     7     8

Concatenating matrices by appending columns

left = [1 3; 2 4];
right = [10 30; 20 40];
wide = cat(2, left, right)

Expected output:

wide =
     1     3    10    30
     2     4    20    40

Building a 3-D array from 2-D slices

slice1 = magic(3);
slice2 = eye(3);
cube = cat(3, slice1, slice2)

Concatenating logical masks without type changes

row = logical([1 0 1]);
mask = cat(1, row, ~row)

Expected output:

mask =
   1   0   1
   0   1   0

Joining character arrays into wider text rows

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

Expected output:

words =
    RunMat
    GPUFun

Concatenating string arrays along rows

names = ["alpha" "beta"];
more = ["gamma" "delta"];
combined = cat(1, names, more)

Appending cell array columns for table-like data

cols1 = {1, 2; 'a', 'b'};
cols2 = {3, 4; 'c', 'd'};
tableCells = cat(2, cols1, cols2)

Keeping gpuArray inputs on the device

G1 = gpuArray(rand(256, 256));
G2 = gpuArray(rand(256, 256));
stacked = cat(3, G1, G2)

Requesting GPU output with the "like" prototype

G = gpuArray(rand(3, 3));
H = cat(3, zeros(3, 3), ones(3, 3), "like", G)

Concatenating complex arrays preserves imaginary parts

z1 = complex([1 2], [3 4]);
z2 = complex([5 6], [7 8]);
joined = cat(2, z1, z2)

Combining empty inputs yields an empty result

emptyRow = zeros(0, 3);
combo = cat(1, emptyRow, emptyRow)

Using cat with coding agents

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

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

Related Array functions

Shape

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

Grouping

accumarray · combinations · discretize · findgroups · groupcounts · grp2idx · splitapply

Sorting Sets

argsort · intersect · ismember · ismembertol · issorted · issortedrows · setdiff · setxor · sort · sortrows · union · unique

Creation

colon · createArray · empty · eye · false · full · inf · linspace · logspace · magic · meshgrid · nan · nchoosek · ndgrid · nonzeros · ones · peaks · perms · rand · randi · randn · randperm · range · sparse · spdiags · speye · spones · sprand · true · zeros

Indexing

find · ind2sub · sub2ind

Introspection

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

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how cat is executed, line by line, in Rust.

  • View the source for cat in Rust on GitHub
  • Learn how the RunMat 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 blazing on any GPU. It is licensed under the Apache 2.0 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
  • How cat works
  • Does RunMat run cat on the GPU?
  • Examples
  • Concatenating matrices by stacking rows
  • Concatenating matrices by appending columns
  • Building a 3-D array from 2-D slices
  • Concatenating logical masks without type changes
  • Joining character arrays into wider text rows
  • Concatenating string arrays along rows
  • Appending cell array columns for table-like data
  • Keeping gpuArray inputs on the device
  • Requesting GPU output with the "like" prototype
  • Concatenating complex arrays preserves imaginary parts
  • Combining empty inputs yields an empty result
  • Using cat with coding agents
  • Related Array functions
  • Shape
  • Grouping
  • Sorting Sets
  • Creation
  • Indexing
  • Introspection
  • Open-source implementation
  • About RunMat