Straightforward COPY and PASTE functions

Allows very simple manual exchange with other applications through the clipboard.
Updated 21 Jan 2015

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

Matlab's CLIPBOARD command allows the user to import and export data to and from other applications. But this command is limited to strings, or requires some mouse work when importing numerical arrays with the 'pastespecial' option.
This submission consists of two functions that make moving simple data from and to Matlab extremely easy. They are used as follows:
1) From Matlab to other application: In Matlab, say copy(x). Then in the other program (eg Excel, Word, Mathematica etc), import with the local Paste function. Depending on what kind of class x is, different material is pushed to the clipboard. For instance, if x is a numerical array, the receiving function will also see numerical data, not a string (as it would when using clipboard('copy',...)).
2) From another application to Matlab: In the other application, use the copy function to place content into the clipboard. Then, in Matlab, say x = paste; Depending of the structure of the data in the clipboard, the program makes x either a numerical array, a cell array, or a string.
See the help provided in the two functions for some examples. The two functions are limited to numerical arrays, cell arrays, and strings. They do not support structs or special classes.
Please comment if you like it or find it useful.

Cite As

Yvan Lengwiler (2024). Straightforward COPY and PASTE functions (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Environment and Settings in Help Center and MATLAB Answers

Inspired by: num2clip: copy numerical arrays to clipboard

Inspired: To Latex, vjmedina/MCTB

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

Copy now supports figures.

bug fix

Corrected a bug that Jiro Doke found (Thank you, Jiro). In addition, copy() now also supports logical arrays.

small bug-fix

Support for table variables (suggestion by Greg).

Three new options are implemented, with allow the handling of unusually formatted numbers or separators (following a suggestion by arnold).

The paste function now tries to identify non-conventional decimal and thousand separators.

Special treatment of empty cells (following a suggestion by Joseph Burgel).

small improvemnt of efficiency

copy now also handles multi-line character arrays

Fixed a small bug in 'paste' and expanded help text.