Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting MATLAB's disp to a text string

Tags:

matlab

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?)

like image 945
Amelio Vazquez-Reina Avatar asked Jul 11 '11 18:07

Amelio Vazquez-Reina


2 Answers

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.

like image 73
Navan Avatar answered Nov 18 '22 06:11

Navan


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.

like image 4
Erik Avatar answered Nov 18 '22 08:11

Erik