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

lsline — Add least-squares fit lines to scatter-style plots.

lsline appends least-squares fit lines to eligible scatter-style series in the current or specified axes. It matches MATLAB's compatibility surface for adding fit lines to scatter plots and marker-only line plots, returning the created line handle or handles when requested.

Syntax

lsline()
lsline(ax)
h = lsline()
h = lsline(ax)

Inputs

NameTypeRequiredDefaultDescription
axAxesHandleYes—Target axes handle.

Returns

NameTypeDescription
hNumericArrayLine graphics handle or vector of line handles.

Errors

IdentifierWhenMessage
RunMat:lsline:InvalidArgumentThe optional axes handle is malformed or extra arguments are supplied.lsline: invalid argument
RunMat:lsline:InternalRunMat cannot construct or register the least-squares line.lsline: internal error

How lsline works

  • lsline() scans the current axes and adds one least-squares line for each visible eligible scatter-style plot.
  • lsline(ax) targets the specified axes without changing other axes.
  • Eligible plots include scatter plots and marker-only line plots. Ordinary line plots with a visible connecting line are ignored.
  • Non-finite X/Y pairs are skipped when computing the fit. A vertical or constant-X eligible series produces a horizontal least-squares line at the mean Y value.
  • If no eligible plots are present, RunMat returns an empty 0x0 handle array.
  • The returned line handle is compatible with get and set for line properties such as XData, YData, Color, LineStyle, LineWidth, and DisplayName.

Examples

Add a least-squares line to a scatter plot

x = [1 2 3 4];
y = [1.2 1.9 3.1 3.8];
scatter(x, y);
h = lsline;

Target a specific axes

ax = subplot(1,2,2);
scatter(ax, [1 2 3], [2 4 6]);
h = lsline(ax);

Inspect the generated line data

scatter([1 2 3], [2 4 6]);
h = lsline;
get(h, 'YData')

Expected output:

ans =
     2     6

Using lsline with coding agents

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

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

FAQ

How is lsline related to refline?⌄

lsline only computes least-squares fit lines for eligible scatter-style plots. refline can do the same when called without coefficients, but it also accepts explicit slope/intercept coefficients for drawing arbitrary reference lines.

Does lsline fit every plot in the axes?⌄

No. MATLAB-style lsline is intended for scatter-style data. RunMat fits scatter plots and marker-only line plots and ignores connected line plots, surfaces, bars, and other graphics objects.

Related Stats functions

Summary

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

Ml

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

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

  • View the source for lsline 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 lsline works
  • Examples
  • Add a least-squares line to a scatter plot
  • Target a specific axes
  • Inspect the generated line data
  • Using lsline with coding agents
  • FAQ
  • Related Stats functions
  • Summary
  • Ml
  • Random
  • Hist
  • Options
  • Open-source implementation
  • About RunMat