Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass command line arguments to a standalone MATLAB executable running on Linux/Unix?

How can I pass command line arguments to a standalone MATLAB executable running on Linux/UNIX?

I need to compile my MATLAB script as a standalone file that can be run on a machine without MATLAB present. It needs to be able to work in a way similar to C's argv[], where you do the following:

Command line:

myfile argument1.txt argument2.txt 

where argument 1 and 2 are the input and output files.

The exact syntax doesn't matter, but it should work like argv[]. What is a function that could do this?


What I mean is that I have MATLAB on my computer, but I need to make an standalone executable that can run on Unix systems WITHOUT MATLAB on those computers (it's a cluster, that only has MATLAB on one node). I need to find a way to make the varargin function without having MATLAB installed on the computer that's running the program. If I can tell MATLAB to put the MATLAB library in each executable, that's OK, as long as it's a complete standalone package.

like image 831
Pilotbaxter007 Avatar asked Jul 26 '10 14:07

Pilotbaxter007


People also ask

How to pass arguments to MATLAB executables?

To pass command-line arguments to a MATLAB executable, you define a single MATLAB function in the executable: the arguments to the function are taken from the command line parameters (the first command-line parameter is the first argument, and so on). For example, create a file echo.

Can you run MATLAB executable without MATLAB?

The MATLAB compiler runtime (MCR), also known as MATLAB Runtime, is a standalone set of shared libraries, MATLAB code, and other files that enables the execution of MATLAB files on computers without an installed version of MATLAB.

What is Varargin MATLAB?

varargin is an input variable in a function definition statement that enables the function to accept any number of input arguments. Specify varargin by using lowercase characters. After any explicitly declared inputs, include varargin as the last input argument .


1 Answers

The MATLAB website has a worked-through example with instructions on how to compile a simple application and how to deploy it on another computer. In essence, you need to install the MATLAB Compiler Runtime together with your application; the installer for the runtime should already be present in your MATLAB compiler installation.

To pass command-line arguments to a MATLAB executable, you define a single MATLAB function in the executable: the arguments to the function are taken from the command line parameters (the first command-line parameter is the first argument, and so on).

For example, create a file echo.m with the following contents:

function exitcode = echo(a, b)  display(a); display(b);  exitcode = 0; 

You can then compile this file and run it with echo 1 2 3, and it will print a=1 b=2.

Note that, when arguments are taken from the command line, they are passed to the function as strings, so you need to convert them to numbers using the str2num function. For instance:

function rc = display_product(a, b)  a = str2num(a); b = str2num(b);  display(a*b);  rc = 0; 
like image 103
Riccardo Murri Avatar answered Oct 09 '22 21:10

Riccardo Murri