Straightforward COPY and PASTE functions
Updated 21 Jan 2015
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.
Yvan Lengwiler (2023). 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
Platform CompatibilityWindows macOS Linux
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!
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Copy now supports figures.
Corrected a bug that Jiro Doke found (Thank you, Jiro). In addition, copy() now also supports logical arrays.
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.