How to redirect Matlab output of a command to a file? [duplicate]
Question
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.
Solution
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.
OTHER TIPS
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow