gca — Return the current axes handle in MATLAB and RunMat.
gca returns the handle for the current axes in the active figure, or in a specific figure when a figure handle is supplied. Optional struct mode returns a snapshot of current axes context for diagnostics and tooling.
Syntax
ax = gca()
ax = gca(fig)
s = gca('struct')Inputs
fig- Type
Any- Required
- Yes
- Description
- Exact native Figure receiver or numeric Figure compatibility handle whose current axes should be returned.
mode- Type
StringScalar- Required
- Yes
- Description
- Only 'struct' is supported.
Returns
ax- Type
Any- Description
- Current axes graphics object; RunMat currently returns its encoded numeric axes handle.
s- Type
Any- Description
- Axes state struct with handle/figure/rows/cols/index fields.
Errors
RunMat:gca:InvalidArgument- When
- Unsupported arguments are provided.
- Message
gca: unsupported arguments
RunMat:gca:TooManyOutputs- When
- More than one output is requested.
- Message
gca: at most one output is supported
Behavior and compatibility
gca() returns a scalar numeric axes handle.
gca(fig) returns the current axes handle for the specified figure handle.
gca('struct') returns a struct with fields handle, figure, rows, cols, and index.
The current axes reflect the active subplot when subplot has been used.
The numeric axes handle can be passed to get and set, including common axes styling such as FontSize.
Unsupported arguments raise gca plotting errors.
Placement
gca returns host-side handles or structs without provider dispatch or numeric GPU kernels. It reads the plotting registry, creating the ordinary default figure when none exists.
Graphics state remains host-owned. Resident control values reject before provider access; resident plotted arrays retain the rendering pipeline.
Whole-call resource accounting, cooperative large host controls, and native/browser presentation require integrated qualification.
Examples
Read the current axes handle caption: % ax is a numeric axes handle
figure(1);
ax = gca()Inspect the active subplot layout
subplot(2, 2, 3);
info = gca("struct")Expected output:
info =
struct with fields:
handle
figure
rows
cols
indexRead the current axes of a specific figure caption: % ax1 is the current axes handle for figure 1
f1 = figure(1);
subplot(2, 2, 3);
f2 = figure(2);
ax1 = gca(f1)Style the current axes
plot(1:3, [1 2 3]);
set(gca, 'FontSize', 10);Using gca with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how gca changes the result.
Run a small gca example, explain the result, then change one input and compare the output.
FAQ
What is special about gca('struct')?⌄
It is a RunMat extension that returns a struct snapshot of the active axes state instead of just the encoded numeric handle.
Does gca reflect subplot selection?⌄
Yes. When a subplot is active, gca reports that subplot's axes handle and metadata.
Can gca inspect a non-current figure?⌄
Yes. Pass a figure handle, for example gca(fig), to read that figure's current axes without changing the active figure.
Does gca run on the GPU?⌄
No. It only reads host-side plotting state.
Related Plotting functions
2D Charts
area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem
Other
addpoints · ancestor · animatedline · autumn · axes · barh · bone · caxis · cla · clf · clim · colorcube · colororder · cool · copper · copyobj · cylinder · daspect · datacursormode · dataTipTextRow · drawnow · fcontour · figure · fill · fill3 · findobj · fsurf · gobjects · gray · groot · hgload · hgsave · hidden · histogram2 · hold · hot · inferno · isgraphics · ishandle · jet · line · lines · linkaxes · magma · openfig · opengl · pan · parula · patch · pink · plasma · plotmatrix · plotyy · polarhistogram · polarplot · polarscatter · print · quiver3 · ribbon · saveas · savefig · sphere · spring · stackedplot · subtitle · summer · suptitle · text · textscatter · textscatter3 · triplot · turbo · viridis · waitbar · winter · wordcloud · xlabel · xlim · xline · xscale · xtickangle · xtickformat · xticklabels · xticks · ylabel · ylim · yline · yscale · ytickangle · ytickformat · yticklabels · yticks · zlim · zoom
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.