How to start matlab from the command line and print on the command line?

I want to run a script on a Windows dos terminal, where the script will display "Hello world" on the terminal I executed this for example

matlab.exe -nosplash -nodesktop -nojvm -wait -r printToCommandLine.m

Where printToCommandLine.m contains:

system (sprintf ('echo Hello world'));

but it only prints in the matlab command window that is generated when the script is executed

+5
source share
1 answer

At first , I'm not sure if the syntax has changed, but I have to call the script without the .m 'file extension:

matlab.exe -nosplash -nodesktop -nojvm -wait -r printToCommandLine 

Otherwise, I will get an error in MATLAB.

Second , it just works, but you can print the current command line output into a log file, for example. 'log.txt' with

 matlab.exe -nosplash -nodesktop -nojvm -wait -logfile "log.txt" -r printToCommandLine 

The log file will be updated at run time. To test this, I created a small example script and looked at how "log.txt" changes at runtime:

 disp('Script execution started. Waiting 10 seconds...') pause(10) disp('...waited 10 seconds.'); 

This is not quite what you wanted, but it gives you the opportunity to get actual information about the current command line output at run time (in a text file).

We use this for automated (remote) testing, to print the output of the MATLAB command line to the console after the tests passed using

 type log.txt 
+1
source

Source: https://habr.com/ru/post/1275802/


All Articles