view — Set or query 3-D camera view angles with MATLAB-compatible view call forms.
view reads or updates azimuth/elevation camera orientation for current or specified axes. It supports MATLAB-compatible forms such as view(2), view(3), view([az el]), and view(az, el).
Syntax
angles = view()
angles = view(ax)
angles = view([az el] | preset)
angles = view(az, el)
angles = view(ax, [az el] | preset)
angles = view(ax, az, el)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
ax | AxesHandle | Yes | — | Axes handle to query. |
angles | NumericArray | Yes | — | Two-element [az el] vector or preset value 2/3. |
az | NumericScalar | Yes | — | Azimuth in degrees. |
el | NumericScalar | Yes | — | Elevation in degrees. |
ax | AxesHandle | Yes | — | Axes handle to set. |
Returns
| Name | Type | Description |
|---|---|---|
angles | NumericArray | Current or assigned view angles as [az el]. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:view:InvalidArgument | Arguments are malformed, wrong arity, wrong shape, or unsupported preset. | view: invalid argument |
RunMat:view:InvalidAxes | Axes target is invalid or no longer exists. | view: invalid axes target |
RunMat:view:Internal | Internal plotting state operation fails. | view: internal operation failed |
How view works
viewwith no angle arguments queries the current[az el]pair.view(2)selects the standard top-down 2-D camera andview(3)restores the standard 3-D camera preset.- Explicit azimuth/elevation values can be passed as two scalars or as a two-element vector.
- View state is subplot-local and does not leak across different axes in a subplot grid.
- Axes handles can be passed explicitly so camera changes target a specific subplot rather than whichever axes happens to be current.
Examples
Set an explicit 3-D camera angle
[X, Y] = meshgrid(linspace(-2, 2, 60), linspace(-2, 2, 60));
Z = sin(X.^2 + Y.^2);
surf(X, Y, Z);
view(45, 30);Use MATLAB-style view presets
[X, Y] = meshgrid(linspace(-3, 3, 40), linspace(-3, 3, 40));
Z = sin(X) .* cos(Y);
surf(X, Y, Z);
view(2);
view(3);Query a subplot-local camera
ax = subplot(1, 2, 2);
plot3(cos(0:0.1:5), sin(0:0.1:5), 0:0.1:5);
view(ax, [60 20]);
get(ax, 'View')Expected output:
% Returns a 1x2 vector [60 20]Using view with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how view changes the result.
Run a small view example, explain the result, then change one input and compare the output.
FAQ
What do azimuth and elevation mean in view(az, el)?⌄
Azimuth is the horizontal rotation around the z-axis (0° looks along the y-axis toward the origin). Elevation is the angle above the x-y plane (0° is level, 90° is directly overhead). view(45, 30) gives the classic isometric-ish perspective for 3-D surfaces.
How do I reset to the default 2-D or 3-D view?⌄
view(2) sets the camera to top-down (azimuth 0, elevation 90) — useful for looking at a surface as a heatmap. view(3) restores the default 3-D camera at [-37.5, 30], which is the standard MATLAB 3-D preset.
Can I set different view angles per subplot?⌄
Yes. View state is subplot-local. Pass the axes handle explicitly to target a specific panel.
ax1 = subplot(1, 2, 1); surf(X, Y, Z); view(ax1, 0, 90);
ax2 = subplot(1, 2, 2); surf(X, Y, Z); view(ax2, 45, 30);Related Plotting functions
More plotting resources
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how view is executed, line by line, in Rust.
- View the source for view 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.