How to redirect Matlab output of a command to a file? [duplicate]

坚强是说给别人听的谎言 提交于 2019-12-02 09:27:00

问题


I want to redirect or copy the output of a Matlab command to a file. How can I do that?

In my case, I have two large structs that I want to compare using the UNIX tool diff.

Example: I can do this in Matlab:

>> s1

s1 = 

      a: 32
    abc: 'example'

>> 

and want a file containing approx:

s1 = 

      a: 32
    abc: 'example'

These solutions are not viable:

  • Copy-pase: can't automate (comfortably).
  • save -ascii: does not work with structs.

回答1:


Have a look at the diary function. E.g.

diary my_file.txt
s1
diary off

The file my_file.txt will then contain exactly what you see on screen.




回答2:


If you need to do it more fine grained there is the evalc function that will store the output to a string.

Later you can output the string into any output channel matlab offers.



来源:https://stackoverflow.com/questions/22008401/how-to-redirect-matlab-output-of-a-command-to-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!