将MATLAB的disp重定向到文本字符串 [英] Redirecting MATLAB's disp to a text string

查看:292
本文介绍了将MATLAB的disp重定向到文本字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设在MATLAB交互式会话中,我从第三方库output = long_execution(input)中调用了一个函数.此函数通过 disp 语句将信息打印到命令窗口.我想捕获此类 disp 可以在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.

是否有一种(非常简单的方法)重定向 disp 到文本字符串?如果是这样,您将如何做? (也许通过 disp 的叠加?)

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

推荐答案

您可以使用evalc函数捕获disp输出.例如

You can use evalc function to capture disp outputs. For example,

    [T, output] = evalc('long_execution(input)');

通常会进入命令窗口的所有内容都会捕获到输出T中.

Anything that would normally go to command window is captured into the output T.

这篇关于将MATLAB的disp重定向到文本字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆