当我运行matlab -nodesktop -r "run myscript"
时,会弹出一个 Matlab 命令窗口并且输出在那里,但我希望输出被定向到 unix 控制台。那么如何让 Matlab 脚本从 Unix 控制台运行以输出到 Unix 控制台呢?
要将数据输出到控制台(最好说是 stdout),您可以使用 MATLAB 函数 fprintf() 并运行它:
user@host $ matlab -nodesktop -r "run new.m; quit"
新.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**
*******************************************************************