I am trying to run Matlab 2013 via PBS and I get the following error:
libXv.so.1: cannot open shared object file: No such file or directory
I can run my code in Matlab's GUI mode though. I tried using LD_PRELOAD to point to the library as under, but that did not help either.
setenv LD_PRELOAD /usr/lib/x86_64-linux-gnu/libXv.so.1
Any suggestions on how to go about resolving this error?
When running Matlab via PBS you run actual Matlab scripts on the nodes of the cluster that probably do not have any GUI components installed including the X client libraries such as libXv.so.1.
You probably do not want to run Matlab in a GUI mode via a batch system unless it is an interactive job. In case you just want to run a script, try specifying matlab command line in your PBS script as follows:
matlab -nodisplay -nodesktop -nojvm -nosplash -r "myfunc"
Where myfunc is the Matlab command that you want to run on the cluster.
Related
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"
The test.m is simple:
function test
disp('Hello!');
The output is displayed in the Matlab Command Window. Is there any way how I can force output to the windows prompt?
Use the command line option -log when you call Matlab from the command line (or any other shell or batch (e.g. cmd or bat) script).
It isn't documented as of Matlab 2017b, but it works.
Side note: -nodisplay isn't supported in the Windows version of Matlab, but if you want to prevent it from displaying figures, use -noFigureWindows instead.
Since R2019b, there is a new command line option, -batch, which redirects the output to the command line and handles other stuff for batch processing. See the documentation for Windows.
matlab -batch "statement to run"
This starts MATLAB without the desktop or splash screen, logs all output to stdout and stderr, exits automatically when the statement completes, and provides an exit code reporting success or error.
I don't know of a way to do it in Windows to get Matlab to actually run in the DOS window which is what you would need for the display to be written in it. (FYI: You can in LINUX - but I assume you need to run in Windows).
For running in Matlab you have 2 alternatives that I can think of:
-logfile FILE on launch which will record all output to a FILE you specify - however how and when the file is written to disk is controlled by Matlab and I haven't tested to see - if your code doesn't do much it might only be written on Matlab exit.
diary FILE in your Matlab command, i.e. -r "diary FILE.TXT; test.m; diary OFF" - this is similar to above - but uses the diary function.
However you can get what you want if you can run your code compiled (I know thats a big if as you may not have the compiler - or if you regularly want to update test.m this is not the most efficient...
When you run a compiled code from a DOS prompt all the terminal messages are written to the DOS prompt. One thing I'd advise if this is suitable is to delete the "splash.png" file from your installation directory to avoid the splash screen displaying when you run from the DOS as its (probably) not needed.
I have found a solution at:
https://www.mathworks.com/matlabcentral/answers/91607-how-can-i-redirect-the-command-window-output-to-stdout-and-stderr-when-running-matlab-7-8-r2009a-i#answer_100958
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);
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
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.
I am using an external solver to run simulations. I am trying to call the external solver with system(cmd) from a MATLAB script. The cmd itself runs fine with no problems from the Terminal (I'm running on OSX). However, every time the MATLAB script runs, the status is 139 - Segmentation Fault. Does anyone know why this might be happening?
When executing the system command this is not the same as running a program from the terminal since you likely have environment variables defined within your terminal session (via ~/.bashrc or ~/.bash_profile) that are going to effect how a program is accessed and run.
If you have environment variables that you need to set for the program to run successfully, use setenv from within MATLAB prior to calling system.
I had the same problem with my Matlab (R2016b), but the solution was exactly the opposite.
Instead of missing variables, system() defined LD_LIBRARY_PATH which redirected to some shared libraries packaged with Matlab that didn't sit well with my program. After clearing LD_LIBRARY_PATH in my script, everything worked fine. You can do that for example with this:
env -u LD_LIBRARY_PATH
This question already has answers here:
Writing log statements to standard output with Matlab
(8 answers)
Closed 6 years ago.
I'm trying to integrate my MATLAB unit tests into Jenkins in a Windows environment. My problem is that I am not able to get the MATLAB output in my Jenkins console, even for a simple disp('Hello World!').
I create a Jenkins free job to execute the following batch command:
matlab -nodisplay -r "disp('Hello World!');exit".
Here is my result:
C:\Jenkins\jobs\runAllTests\workspace>matlab -nodisplay -r "disp('Hello World!');exit"
C:\Jenkins\jobs\runAllTests\workspace>exit 0
Finished: SUCCESS
Of course, I want to use Jenkins to execute a script to run several unit tests. But the problem is the same, I am not able to catch the MATLAB outputs.
Thanks in advance for any help.
I finally manage to get the matlab output in the console.
I follow a tip given in #AndyCampbell blog by #Guy Starbuck:
start /wait matlab -nodesktop -nosplash -minimize -wait -r "disp('Hello World!');exit" -logfile unittestlog.txt
set output=%errorlevel%
MORE unittestlog.txt
EXIT %output%
thanks all for your help.
You need to add -wait to the MATLAB command.
On Windows, Jenkins wraps the command in a batch file that returns immediately, and therefore doesn't capture the output (and by the way, it will also always exit with a success status even if MATLAB itself didn't).
By adding -wait, it will delay the exit until MATLAB has finished, and it will also return with the appropriate exit status.
PS Also see this excellent series of posts by #AndyCampbell on integrating MATLAB with Jenkins.
Edit:
The above works for me. But here's a couple of other things I would check, as they've been gotchas for me when I was getting it set up - perhaps they will help you too:
Make sure the build step is an "Execute Windows batch command" step rather than an "Execute shell" step, as it's a pain to get the unix utilities installed and running on Windows
Make sure that you have the right type of quote marks in the MATLAB build command. They need to be straight quotes, not curly quotes - both the single and double ones
If you copied and pasted the MATLAB build command into Jenkins, make sure you didn't accidentally paste in any extra invisible characters - try typing the command directly into Jenkins
Make sure there are no licensing issues - for example, Jenkins may be running as user1 and will call MATLAB as user1, but MATLAB is licensed to user2. If you call MATLAB with -nodesktop in this case it will just silently fail (and may even leave a zombie MATLAB process hanging around, with an invisible license error dialog, that you can only quit from with Task Manager)
To assist in troubleshooting, you can add -logfile \path\to\logfile.txt to your MATLAB command, which can diagnose some issues. You can also use a startup.m file and/or a finish.m file - these should run at startup (before your build command) and just before exit (after your build command). Finally you could try using a build command that does something simple to the filesystem, rather than a disp (this would diagnose whether it's an issue with MATLAB running at all, or an issue with Jenkins collecting its output).
Matlab provides the sim command that can be used in a Matlab script to call and execute a Simulink model. But the function seems to be restricted to models that only run in Normal mode. When I try to call a Simulink model that runs in External mode, Matlab halts the script and flags it as an error. Besides being a nuisance it seems to me an unnecessary restriction on what could be a very useful application.
In any event is there a work around, perhaps a different command that I can use to run the Simulink diagram in External mode from the Matlab script?
I did try using the Matlab DOS shell command (using !) but it requires opening another instance of Matlab.
External Mode doesn't run a simulation, rather it is a mechanism for using the Simulink model's front end as a way of changing and viewing data that is running elsewhere (e.g. an executable running on the same machine as the model, or code running on an external processor).
To do that from the command line (or within code) you need to use a combination of the following commands:
>> set_param(gcs,'SimulationMode','external') % put model into External Mode
>> set_param(gcs,'SimulationCommand','connect') % connect to the executable
>> set_param(gcs,'SimulationCommand','start') % Start the executable
>> set_param(gcs,'SimulationCommand','stop') % Stop the executable
I am trying to run a Matlab script from Windows command prompt but I can't execute it sometimes. The script runs fine when manually launched. Matlab version is 2011a and Windows is Server 2003 SP2. Details:
Script mytask.m is located inside say E:\Production\Project. This is SAVED on Matlab's path.
When I place mytask.m inside bin folder, it executes fine by the command:
`C:\Program Files\MATLAB\R2011a\bin>matlab -r mytask`
If you delete it and try to access it at its original location, the script doesn't run although Matlab editor window is launched:
`C:\Program Files\MATLAB\R2011a\bin>matlab -r "E:\Production\Project\mytask"
Any suggestions please? Thanks.
The syntax for matlab -r is
matlab -r "statement"
In other words, you need to provide some executable commands as the statement. For example:
matlab -r "run E:\Production\Project\mytask"
However, it seems that matlab does not load the customized paths in this way. If you have some customized paths, you probably have to define them in startup.m and place this startup.m in the directory where you invoke matlab.
I didn't check myself, but if you define E:\Production\Project\ as the path in startup.m, you probably can run matlab -r mytask without problem, as mytask will be recognized as a user function/script.
A simple example of startup.m
path(path, 'E:\Production\Project\');