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
    • addpoints
    • ancestor
    • animatedline
    • area
    • axes
    • axis
    • bar
    • barh
    • box
    • caxis
    • cla
    • clf
    • clim
    • colorbar
    • colorcube
    • colormap
    • colororder
    • contour
    • contour3
    • contourf
    • copyobj
    • daspect
    • datacursormode
    • dataTipTextRow
    • errorbar
    • fcontour
    • figure
    • fill
    • fill3
    • findobj
    • fsurf
    • gca
    • gcf
    • get
    • gobjects
    • grid
    • groot
    • heatmap
    • hgload
    • hgsave
    • hidden
    • hist
    • histogram
    • histogram2
    • hold
    • image
    • imagesc
    • imshow
    • legend
    • line
    • linkaxes
    • loglog
    • mesh
    • meshc
    • openfig
    • opengl
    • pan
    • parula
    • patch
    • pie
    • plot
    • plot3
    • plotmatrix
    • plotyy
    • polarhistogram
    • polarplot
    • polarscatter
    • print
    • quiver
    • quiver3
    • ribbon
    • saveas
    • savefig
    • scatter
    • scatter3
    • semilogx
    • semilogy
    • set
    • sgtitle
    • shading
    • sphere
    • stackedplot
    • stairs
    • stem
    • subplot
    • subtitle
    • suptitle
    • surf
    • surfc
    • text
    • textscatter
    • textscatter3
    • title
    • triplot
    • view
    • waitbar
    • wordcloud
    • xlabel
    • xlim
    • xline
    • xscale
    • xtickangle
    • xtickformat
    • xticklabels
    • xticks
    • ylabel
    • ylim
    • yline
    • yscale
    • ytickangle
    • ytickformat
    • yticklabels
    • yticks
    • zlabel
    • zlim
    • zoom

sphere — Generate or plot unit-sphere coordinate grids with MATLAB-compatible sphere syntax.

sphere creates X, Y, and Z coordinate matrices for a unit sphere. With no outputs it renders the sphere in the current axes; with explicit outputs it returns coordinate grids sized (n+1)-by-(n+1), where n is the number of faces per dimension and defaults to 20.

Syntax

sphere()
sphere(n)
X = sphere()
X = sphere(n)
[X,Y] = sphere()
[X,Y] = sphere(n)
[X,Y,Z] = sphere()
[X,Y,Z] = sphere(n)

Inputs

NameTypeRequiredDefaultDescription
nIntegerScalarNo20Number of surface faces per dimension; outputs have size (n+1)-by-(n+1).

Returns

NameTypeDescription
XNumericArrayX coordinates on the unit sphere.
YNumericArrayY coordinates on the unit sphere.
ZNumericArrayZ coordinates on the unit sphere.

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

Errors

IdentifierWhenMessage
RunMat:sphere:OutputCountMore than three outputs are requested.sphere: too many output arguments; maximum is 3
RunMat:sphere:InvalidArgumentMore than one input argument is supplied.sphere: expected zero or one input argument
RunMat:sphere:InvalidArgumentThe n argument is not a finite non-negative integer scalar.sphere: n must be a finite non-negative integer scalar
RunMat:sphere:OutOfMemoryThe requested coordinate grid is too large for RunMat's bounded allocation policy.sphere: requested grid is too large
RunMat:sphere:InternalCoordinate tensor construction or plotting fails unexpectedly.sphere: internal operation failed

How sphere works

  • sphere and sphere(n) in statement form plot a unit sphere in the current axes.
  • X = sphere(n) returns the X-coordinate grid.
  • [X, Y] = sphere(n) returns the X and Y coordinate grids.
  • [X, Y, Z] = sphere(n) returns all coordinate grids for use with surf, mesh, or other 3-D plotting functions.
  • The default grid uses n = 20, producing 21-by-21 coordinate tensors.
  • n must be a finite non-negative integer scalar. sphere(0) returns a single unit-sphere point.
  • Typed integer storage for n is a RunMat-only extension because the compatibility target specifies an integer value without enumerating storage classes. RunMat decodes it structurally without floating-point conversion.

Does RunMat run sphere on the GPU?

Coordinate generation is CPU-side and deterministic.

The coordinate outputs can be passed to surf(X, Y, Z), which supports full parametric coordinate matrices for this workflow.

GPU memory and residency

sphere returns host tensors. Statement-form rendering builds a host-side 3-D mesh and follows the normal plotting fallback behavior.

Examples

Plot the default unit sphere

sphere;
axis equal;
view(45, 25);

Return coordinate grids and plot them manually

[X, Y, Z] = sphere(40);
surf(X, Y, Z);
axis equal;
shading interp;
colormap('parula');

Use sphere coordinates in another expression

[X, Y, Z] = sphere(30);
R = sqrt(X.^2 + Y.^2 + Z.^2);
max(abs(R(:) - 1))

Using sphere with coding agents

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

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

FAQ

What size are the outputs?⌄

sphere(n) returns coordinate tensors with size (n+1)-by-(n+1). The default sphere uses n = 20, so the default output size is 21-by-21.

How do I get the coordinates without plotting?⌄

Request outputs explicitly, for example [X, Y, Z] = sphere(50). Statement-form calls with no outputs render directly into the current axes.

Does sphere return GPU tensors?⌄

No. sphere constructs host coordinate tensors. Use gpuArray on the outputs if a subsequent numeric pipeline needs GPU residency.

Related Plotting functions

2D Charts

area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem

3D & Surface

contour · contour3 · contourf · mesh · meshc · plot3 · quiver · scatter3 · surf · surfc

Images

image · imagesc · imshow

Axes & Layout

axis · box · grid · sgtitle · subplot · title · view · zlabel

Appearance

colorbar · colormap · legend · shading

Handle Access

gca · gcf · get · set

Other

addpoints · ancestor · animatedline · axes · barh · caxis · cla · clf · clim · colorcube · colororder · copyobj · daspect · datacursormode · dataTipTextRow · fcontour · figure · fill · fill3 · findobj · fsurf · gobjects · groot · hgload · hgsave · hidden · histogram2 · hold · line · linkaxes · openfig · opengl · pan · parula · patch · plotmatrix · plotyy · polarhistogram · polarplot · polarscatter · print · quiver3 · ribbon · saveas · savefig · stackedplot · subtitle · suptitle · text · textscatter · textscatter3 · triplot · waitbar · wordcloud · xlabel · xlim · xline · xscale · xtickangle · xtickformat · xticklabels · xticks · ylabel · ylim · yline · yscale · ytickangle · ytickformat · yticklabels · yticks · zlim · zoom

Open-source implementation

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

  • View the source for sphere 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 sphere works
  • Does RunMat run sphere on the GPU?
  • GPU memory and residency
  • Examples
  • Plot the default unit sphere
  • Return coordinate grids and plot them manually
  • Use sphere coordinates in another expression
  • Using sphere with coding agents
  • FAQ
  • Related Plotting functions
  • 2D Charts
  • 3D & Surface
  • Images
  • Axes & Layout
  • Appearance
  • Handle Access
  • Other
  • Open-source implementation
  • About RunMat