Straightforward COPY and PASTE functions

Allows very simple manual exchange with other applications through the clipboard.
4K Downloads
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 (https://www.mathworks.com/matlabcentral/fileexchange/28016-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
Categories
Find more on Environment and Settings in Help Center and MATLAB Answers
Acknowledgements

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
1.13.0.0

Copy now supports figures.

1.12.0.0

bug fix

1.11.0.0

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

1.10.0.0

small bug-fix

1.9.0.0

Support for table variables (suggestion by Greg).

1.7.0.0

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

1.5.0.0

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

1.4.0.0

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

1.3.0.0

small improvemnt of efficiency

1.2.0.0

copy now also handles multi-line character arrays

1.1.0.0

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

1.0.0.0