Home > Applications > CopyPaste > paste.m



PASTE copies the content of the clipboard to a variable; creates a


function x = paste(dec,sep,lf)


 PASTE copies the content of the clipboard to a variable; creates a
 string, a cell array, or a numerical array, depending on content.

   x = paste;
   x = paste(dec,sep,lf);

 The program will try to create an array. For this to succeed, the
 material that is passed from the clipboard must be a tab delimited array,
 such as produced by Excel's copy command. If the content does not have
 this structure, the program simply returns a string. If the content is an
 array, x will be a numerical array if all its components qualify as
 numerical. If not, it will be a cell array.

 Optional arguments:
   dec   Single character that indicates the decimal separator. Default is
         the period ('.').
   sep   Single character that indicates how horizontal neigbors of a
         matrix or cell array are separated. Default is the tabulator code
         (char 9).
   lf    Single character that indicates how rows are separated.(lf stands
         for line feed). Default is the line feed code (char 10).


 1) If the clipboard contains 'George's job is to chop wood.', then
    x = paste produces x = 'George's job is to chop wood.'

 2) If the content of the clipboard is a simple text with multiple lines
    (copied from Notepad or Word or similar), then x = paste produces a
    cell array with one column and one row per line of the input so each
    line of text will be separated in different cells. For example, if you
    copy the follwing text from some other program,

       Manche meinen lechts und rinks kann man nicht velwechsern.
       Werch ein Illtum!

    then, in Matlab, x = paste produces a 2x1 cell array with

       x{1} = 'Manche meinen lechts und rinks kann man nicht velwechsern.'
       x{2} = 'Werch ein Illtum!'

    [Note: x = clipboard('copy') would produce just a string in this case,
    not an array of stringcells, so choose the code that is most useful for
    your purpose.]

 3) However, if your text contains an equal number of tabs on each line,
    for instance because you've copied something like this from Word,
      1  ->  item 1
      2  ->  item 2
      3  ->  item 3
    where -> denotes TABs, then x = paste produces a 3x2 cell array,
      x = 
         [1]    'item 1'
         [2]    'item 2'
         [3]    'item 3'

 4) If the clipboard contains an array of cells, e.g.
         1  2  3
         4  5  6
    for instance by copying these six cells from an Excel spreadsheet,
    then x = paste makes a 2x3 array of doubles with the same content.
    The same is true if there are NaN cells. So if the Excel excerpt was
         1     2     3
         4   #N/A    6
    then x =
         1     2     3
         4   NaN     6

 5) If the cell collection in the clipboard is
         A  1.3  NaN
    then x will not be a numerical array, but a 1x3 cell array, with
     x = 
        'A'    [1.3000]    [NaN]
    so x{1} is a string, but x{2} and x{3} are doubles.

 6) If the clipboard contains '1,2', then x=paste with no arguments will
    be 12 (because Matlabs str2double('1,2') interprets this as the number
    12). However, x=paste(',') will return 1.2

 7) If the clipboard contains '1,2 & 100', then x=paste with no arguments
    will return just the string '1,2 & 100'. x=paste(',','&'), on the
    other hand, will return a numerical array [1.2, 100].

 Here is a practical example:
   In Excel, select your data, say, a sample of observations organized in
   a few columns. Place them into the clipboard with Ctrl-C.
   Now switch to Matlab and say
       x = paste;
   This puts the data that you copied in Excel into a variable x in
   Matlab's workspace.
   Next, you can analyze the data. For instance, compute the principal
   components (an analysis that is not readily available in Excel), and
   push the result back into the clipboard,
       [c,s] = princomp(x);
   Now, back in Excel, you can paste the result into your spreadsheet with
 This program was selected 'Pick of the Week' on March 7, 2014. :-)

 Author : Yvan Lengwiler
 Release: 1.51
 Date   : 2014-03-19



This function calls: This function is called by:
Generated on Mon 26-Nov-2018 15:08:42 by m2html © 2005. iFit (c) E.Farhi/ILL EUPL 1.1