Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
627 views
in Technique[技术] by (71.8m points)

command line - suppress start message of Matlab

I want to call matlab in bash non-interactively and use its result outside Matlab.

For example, I have a script test.m

rand(3,4)
quit

When I execute in bash

$ matlab -nosplash -nodesktop -nodisplay -r test
Warning: No window system found.  Java option 'MWT' ignored

                        < M A T L A B (R) >
              Copyright 1984-2008 The MathWorks, Inc.
                     Version 7.7.0.471 (R2008b)
                         September 17, 2008


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


ans =

0.8147    0.9134    0.2785    0.9649
0.9058    0.6324    0.5469    0.1576
0.1270    0.0975    0.9575    0.9706

Is it possible to suppress the start message of Matlab and only show the results also without "ans=".

Note I am asking a general question not just for this example.

Thanks and regards!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try using the -logfile command line option:

-logfile log         - Make a copy of any output to the command window
                       in file log. This includes all crash reports.

Then you can easily remove the first few lines using any way you want (sed for example). Example:

matlab.exe -nosplash -nodesktop -nojvm -logfile out.log -r 'rand(3,3), exit'
sed '1,5d' out.log

Also if you are running from a script where you need it to finish running before continuing, use the -wait option:

-wait      - MATLAB is started by a separate starter program
           which normally launches MATLAB and then immediately
           quits. Using the -wait option tells the starter
           program not to quit until MATLAB has terminated.
           This option is useful when you need to process the
           the results from MATLAB in a script. The call to
           MATLAB with this option will block the script from
           continuing until the results are generated.

More info on MATLAB startup options can be found here, or in the matlab executable reference pages: Windows/Unix


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...