This question already has an answer here:
- Print A Matlab Struct to a Text File 3 answers
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.
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.
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