强制将Matlab输出输出到命令行 [英] Force Matlab output to command line

查看:112
本文介绍了强制将Matlab输出输出到命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows命令提示符下运行MATLAB脚本:

I am running a MATLAB script from the Windows command prompt:

"C:\Program Files\MATLAB\R2014B\bin\matlab" -nodisplay -nosplash -nodesktop -wait -r "test.m"

test.m很简单:

The test.m is simple:

function test
disp('Hello!');

输出显示在Matlab命令窗口中.有什么方法可以强制输出到Windows提示符?

The output is displayed in the Matlab Command Window. Is there any way how I can force output to the windows prompt?

推荐答案

我在以下位置找到了解决方案:

I have found a solution at:

https://www.mathworks.com/matlabcentral/answers/91607-how-can-i-redirect-the-command-window-在运行matlab-7-8-r2009a-i#answer_100958

为方便起见,我将在此处复制它.首先,我需要修改matlab脚本以输出到文本文件:

I will replicate it here for convenience. First I need to modify the matlab script to output to a text file:

function test
fid=fopen('output.txt','w');
fprintf(fid,'Hello!');
fclose(fid);

然后,我应该使用bat文件和一个附加命令来运行Matlab,以显示output.txt的内容:

Then I should run the Matlab using a bat file with one additional command to display the contents of the output.txt:

"C:\Program Files\MATLAB\R2014B\bin\matlab" -nodisplay -nosplash -nodesktop -wait -r "test.m"
type output.txt

type 命令将在命令窗口中显示"output.txt"的内容.所以@matlabgui 的回答就差不多了.谢谢.

The type command will display the contents of 'output.txt' in the command window. So answer from @matlabgui was almost there. Thank you.

这不是一个非常优雅的解决方案,但是它可以工作.

It is not a very elegant solution, but it works.

这篇关于强制将Matlab输出输出到命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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