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
    • 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

nchoosek — Return a binomial coefficient or all k-combinations of a vector.

nchoosek(n, k) returns the binomial coefficient for selecting k items from scalar n. nchoosek(v, k) returns a matrix whose rows contain every k-element combination from vector v in input order.

Syntax

b = nchoosek(n, k)
C = nchoosek(v, k)

Inputs

NameTypeRequiredDefaultDescription
n_or_vAnyYes—Nonnegative integer scalar n or vector v containing choices.
kNumericScalarYes—Number of choices to select.

Returns

NameTypeDescription
CAnyBinomial coefficient or matrix whose rows contain all selected combinations.

Errors

IdentifierWhenMessage
RunMat:nchoosek:InvalidInputInputs are missing, malformed, unsupported, or not valid nonnegative integer choices.nchoosek: invalid input
RunMat:nchoosek:TooLargeThe combinations matrix would exceed RunMat's supported materialisation limit.nchoosek: output is too large
RunMat:nchoosek:InternalOutput allocation or container construction failed.nchoosek: internal error

How nchoosek works

  • Scalar coefficient mode accepts nonnegative integer numeric scalars. n and k must have the same type unless one input is double, and mixed double/nondouble inputs return the nondouble class when the result fits.
  • Vector mode accepts numeric, complex, logical, and character vectors, including row vectors, column vectors, and empty vectors.
  • For vector inputs, the output has k columns and one row per combination.
  • k = 0 returns a 1-by-0 empty combinations matrix.
  • When k is greater than the vector length, vector mode returns a 0-by-k empty matrix.
  • Unsupported containers such as string arrays, cells, structs, objects, and sparse arrays raise an input error.

Does RunMat run nchoosek on the GPU?

GPU inputs are gathered; no GPU kernels are launched.

GPU memory and residency

The result is a host value.

Examples

Compute a binomial coefficient

b = nchoosek(5, 2)

Expected output:

b = 10

List combinations from a numeric vector

C = nchoosek([10 20 30], 2)

Expected output:

C = [10 20; 10 30; 20 30]

List character combinations

C = nchoosek('abc', 2)

Expected output:

C = ['ab'; 'ac'; 'bc']

Using nchoosek with coding agents

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

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

FAQ

Does nchoosek run on the GPU?⌄

No GPU kernel is launched. RunMat gathers gpuArray inputs and materializes the scalar or combinations matrix on the host.

Why can nchoosek(v, k) fail for large vectors?⌄

The number of output rows grows combinatorially. RunMat rejects outputs that exceed its materialization limit rather than attempting an impractically large allocation.

Related Array functions

Creation

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

Grouping

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

Sorting Sets

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

Shape

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

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 nchoosek is executed, line by line, in Rust.

  • View the source for nchoosek 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 nchoosek works
  • Does RunMat run nchoosek on the GPU?
  • GPU memory and residency
  • Examples
  • Compute a binomial coefficient
  • List combinations from a numeric vector
  • List character combinations
  • Using nchoosek with coding agents
  • FAQ
  • Related Array functions
  • Creation
  • Grouping
  • Sorting Sets
  • Shape
  • Indexing
  • Introspection
  • Open-source implementation
  • About RunMat