简体   繁体   中英

how to get matlab's output which appeared in command window

How to get the matlab's output? NOT the whole output(I know diary can help)

A easy example :

>> st = rng
st = 
     Type: 'twister'
     Seed: 0
    State: [625x1 uint32]

what I want is to copy the output to clipboard. when I use clipboard function, the error occurs:

>> clipboard('copy', st)
Error using mat2str (line 54)
Input matrix must be numeric.
Error in clipboard (line 56)
        stuff = mat2str(stuff); 

Can I get the output strings to the clipboard easily instead of use mouse select...copy...

Thanks!

add :

Thanks,yuk. Copy the DISP representation is what I wanted.

but could I get something in the clipboard like this after I run the command toString1(rng) :

   >> rng
   ans = 
       Type: 'twister'
       Seed: 11284109
      State: [625x1 uint32]

To copy a matrix to clipboard I'd recommend MAT2CLIP FileExchange submission. It supports not only strings or numeric matrices, but also mixed cell array, logical, etc.

It does not support structures although. If you need to copy individual fields you can still use mat2clip. You can set a for-loop through structure fields and use pause to paste the fields from clipboard.

If you are interested to copy the whole structure or its DISP representation check this SO question - How to get result of DISP as return parameter into a variable?

One solution from this question is to get DISP output to a string, which you can copy to clipboard with mat2clip (universal for any object with display method):

toString = @(x) evalc('disp(x)');
mystring = toString(mystruct);

Another answer recommends STRUCT2STR from FileExchange. Check also STRUCT2STR recursive .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM