Say that, on a MATLAB interactive session, I call a function from a third party library output = long_execution(input)
. This function prints information via disp
statements to the command window. I would like to capture the output of such disp
statements on a text string that I can manipulate in MATLAB.
Is there a (hopefully easy) way of redirecting the output of disp
to a text string? If so, how would you do it? (maybe via the overlading of disp
?)
You can use evalc function to capture disp outputs. For example,
[T, output] = evalc('long_execution(input)');
Anything that would normally go to command window is captured into the output T.
If everything is going into stdout, you can use the diary
function to capture that and write it to file, then after execution you can use any number of matlab file reading utilities to parse through it. You might also find the function tempdir
and tempname
useful in this context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With