copyobj — Copy plot-child graphics objects to an axes or figure parent.
copyobj duplicates supported graphics objects and returns fresh graphics handles. RunMat currently supports plot-child object copies, including line, scatter, bar, stairs, stem, area, quiver, image, heatmap, binscatter, surface, patch, line3, scatter3, contour, fcontour, fsurf, constant-line, pie, and histogram-backed plot children.
Syntax
hnew = copyobj(h, parent)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
h | Any | Yes | — | Graphics object handle or handle array to copy. |
parent | Any | Yes | — | Destination axes or figure handle. |
Returns
| Name | Type | Description |
|---|---|---|
hnew | NumericArray | Copied graphics object handle or handle array. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:copyobj:InvalidArgument | Argument count, source handle, or target parent handle is invalid or unsupported. | copyobj: invalid argument |
RunMat:copyobj:Internal | Internal graphics state lookup or copy registration fails. | copyobj: internal operation failed |
How copyobj works
copyobj(h, parent)copies each plot-child handle inhto an axes or figure parent.- When
parentis an axes handle, copied objects are inserted into that axes. - When
parentis a figure handle, copied objects are inserted into the figure's active axes. - A scalar parent is applied to every source handle; same-sized source and parent arrays copy each source into the corresponding parent; a scalar source can be copied into each parent in a parent array.
- Handle arrays preserve the controlling input shape and receive fresh handle values.
- RunMat validates the whole source/parent copy plan before mutating graphics state, so invalid handle arrays do not leave partial copies behind.
- Copied plot children preserve their plotted geometry and readable/writable plot-child properties such as
Type,Parent, data vectors, line styling, and display names. - Figure, axes, text, legend, ruler, and root-object deep copies are rejected with
RunMat:copyobj:InvalidArgumentrather than silently returning shallow placeholders.
Does RunMat run copyobj on the GPU?
copyobj performs no provider dispatch because graphics object copying is a host graphics-registry operation.
When copied plot elements were originally built from GPU-resident input data, the existing plot-state representation is cloned; no additional CPU/GPU transfer is initiated by copyobj itself.
GPU memory and residency
copyobj returns host-side numeric graphics handles. It does not gather, transform, or upload GPU arrays.
Examples
Copy a line to another axes
h = plot(1:3, [1 4 9], 'DisplayName', 'source');
ax2 = subplot(1,2,2);
h2 = copyobj(h, ax2);
get(h2, 'Parent') == ax2Expected output:
ans = trueCopy a handle array to the same parent
h(1) = plot(1:3);
h(2) = plot(3:-1:1);
ax2 = subplot(1,2,2);
h2 = copyobj(h, ax2);
size(h2)Expected output:
ans = [1 2]Copy one object into two parent axes
h = plot(1:3);
ax1 = subplot(1,2,1);
ax2 = subplot(1,2,2);
h2 = copyobj(h, [ax1 ax2]);
size(h2)Expected output:
ans = [1 2]Using copyobj with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how copyobj changes the result.
Run a small copyobj example, explain the result, then change one input and compare the output.
FAQ
Does copyobj copy figures or axes?⌄
Not yet. This implementation covers plot-child graphics objects and reports a deterministic invalid-argument error for figure, axes, text, legend, ruler, and root deep-copy requests.
Does copying share mutable plot properties with the source?⌄
No. The copied plot receives a fresh handle and independent plot state.
Does copyobj launch GPU kernels?⌄
No. It operates on host-side graphics metadata. Plot geometry already stored in graphics state is cloned without provider dispatch.
Related Plotting functions
2D Charts
area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem
Other
addpoints · ancestor · animatedline · axes · barh · cla · clf · colorcube · colororder · daspect · datacursormode · dataTipTextRow · fcontour · figure · 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 · sphere · stackedplot · subtitle · suptitle · textscatter · textscatter3 · triplot · waitbar · wordcloud · xline · xscale · xtickangle · xtickformat · xticklabels · xticks · yline · yscale · ytickangle · ytickformat · yticklabels · yticks · zoom
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how copyobj is executed, line by line, in Rust.
- View the source for copyobj 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.