将Matlab输出打印到Unix控制台

时间:2013-11-13 17:14:42

标签: matlab

当我运行matlab -nodesktop -r "run myscript"时,会弹出一个Matlab命令窗口,输出就在那里,但我希望将输出定向到unix控制台。那么如何从Unix控制台运行Matlab脚本输出到Unix控制台呢?

1 个答案:

答案 0 :(得分:2)

要将数据输出到控制台(更好地说是stdout),您可以使用MATLAB函数fprintf()并运行它:

user@host $ matlab -nodesktop -r "run new.m; quit"

new.m:

noise_gain = 0.5;
filter_length = 128;

fprintf('*******************************************************************\n');
fprintf('** Starting processing for noise level %f and filter length %d**\n',noise_gain,filter_length);
fprintf('*******************************************************************\n');

它提供输出:

*******************************************************************
** Starting processing for noise level 0.500000 and filter length 128**
*******************************************************************

您也可以将输出发送到文件(out.txt):

user@host $ matlab -nodesktop -r "run new.m; quit"> out.txt; cat out.txt 

                               < M A T L A B (R) >
                     Copyright 1984-2012 The MathWorks, Inc.
                       R2012b (8.0.0.783) 64-bit (glnxa64)
                                 August 22, 2012


To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.

*******************************************************************
** Starting processing for noise level 0.500000 and filter length 128**
*******************************************************************