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
    • bayesopt
    • classify
    • confusionmat
    • crossvalind
    • cvpartition
    • fitclinear
    • fitctree
    • fitlm
    • kmeans
    • knnsearch
    • lasso
    • lassoglm
    • linkage
    • lscov
    • mnrfit
    • optimizableVariable
    • pdist
    • pdist2
    • perfcurve
    • predict
    • regress
    • ridge
    • squareform
    • test
    • training
    • tsne

confusionmat — Compute a confusion matrix from true and predicted class labels.

confusionmat(group,grouphat) compares true class labels in group with predicted labels in grouphat and returns a matrix whose rows are true classes and columns are predicted classes.

Syntax

C = confusionmat(group, grouphat)
C = confusionmat(group, grouphat, Name, Value)
[C,order] = confusionmat(___)

Inputs

NameTypeRequiredDefaultDescription
groupAnyYes—True class labels.
grouphatAnyYes—Predicted class labels.
nameValuePairsAnyVariadic—Name-value options such as Order.

Returns

NameTypeDescription
CNumericArrayConfusion matrix with true labels in rows and predicted labels in columns.
orderAnyClass labels corresponding to rows and columns of C.

Returned values from confusionmat depend on how many outputs the caller requests.

Errors

IdentifierWhenMessage
RunMat:confusionmat:InvalidArgumentLabel vectors, dimensions, order labels, or name-value options are malformed.confusionmat: invalid argument
RunMat:confusionmat:InternalRunMat cannot allocate or construct confusion matrix outputs.confusionmat: internal error

How confusionmat works

  • group and grouphat must contain the same number of labels.
  • MATLAB-compatible inputs are single, double, logical, string, character-row, categorical, and cell-string labels. In RunMat mode, all eight typed-integer classes are also accepted as an explicit extension, without conversion through floating point. Text label families can be mixed between string, char, cell-string, and categorical inputs.
  • Without an explicit order, numeric labels are sorted ascending, text labels follow first appearance across group then grouphat, categorical labels follow category order for observed categories, and logical labels are ordered false then true.
  • confusionmat(group,grouphat,'Order',order) uses the supplied class order, requires every nonmissing label in group and grouphat to appear in order, and includes zero rows or columns for extra order labels that do not appear in the data.
  • Rows with missing true or predicted labels are omitted. Numeric NaN, empty text, and <missing> text are treated as missing labels.
  • [C,order] = confusionmat(...) returns the class labels corresponding to the rows and columns of C. Typed-integer extension inputs preserve their exact class and values in order, including int64 and uint64 values above flintmax.

Examples

Build a numeric confusion matrix

truth = [1; 1; 2; 2];
pred = [1; 2; 2; 1];
[C,order] = confusionmat(truth, pred)

Expected output:

C is [1 1; 1 1] and order is [1; 2].

Use an explicit class order

C = confusionmat(["cat";"dog";"dog"], ["dog";"dog";"cat"], 'Order', ["dog";"cat"])

Expected output:

Rows and columns are ordered as dog, then cat.

Using confusionmat with coding agents

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

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

FAQ

Does confusionmat normalize counts?⌄

No. It returns raw counts. Normalize rows or columns explicitly after computing C.

How are labels not present in an explicit Order handled?⌄

When Order is supplied, it must contain every nonmissing true and predicted label. Extra order labels are allowed and produce zero rows or columns.

Related Stats functions

Ml

bayesopt · classify · crossvalind · cvpartition · fitclinear · fitctree · fitlm · kmeans · knnsearch · lasso · lassoglm · linkage · lscov · mnrfit · optimizableVariable · pdist · pdist2 · perfcurve · predict · regress · ridge · squareform · test · training · tsne

Summary

binocdf · boxplot · cdf · cdfplot · chi2cdf · corr · corrcoef · corrcov · cov · cov2corr · dummyvar · ecdf · filloutliers · fitdist · geomean · grpstats · harmmean · icdf · isoutlier · kstest · kurtosis · lsline · mad · mode · nanmax · normalize · normcdf · norminv · normpdf · onehotdecode · onehotencode · pdf · prctile · quantile · refline · rmse · skewness · tabulate · tcdf · tiedrank · tinv · tpdf · ttest2 · wblinv

Random

binornd · bootstrp · datasample · dividerand · exprnd · gamrnd · lhsdesign · mvnrnd · normrnd · random · randsample · rng · trnd · unidrnd · unifrnd · wblrnd

Hist

histc · histcounts · histcounts2

Options

statget · statset

Open-source implementation

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

  • View the source for confusionmat 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 confusionmat works
  • Examples
  • Build a numeric confusion matrix
  • Use an explicit class order
  • Using confusionmat with coding agents
  • FAQ
  • Related Stats functions
  • Ml
  • Summary
  • Random
  • Hist
  • Options
  • Open-source implementation
  • About RunMat