Main Content

Standalone Applications and Arguments


You can create a standalone to run the application without passing or retrieving any arguments to or from it.

However, arguments can be passed to standalone applications created using MATLAB® Compiler™ in the same way that input arguments are passed to any console-based application.

The following are example commands used to execute an application called filename from Windows® or Linux® command prompt with different types of input arguments.

Pass File Names, Numbers or Letters, Matrices, and MATLAB Variables

To Pass....Use This Syntax....Notes
A file named helpfilefilename helpfile 
Numbers or lettersfilename 1 2 3 a b cDo not use commas or other separators between the numbers and letters you pass.
Matrices as inputfilename "[1 2 3]" "[4 5 6]"Place double quotes around input arguments to denote a blank space.
MATLAB variables
for k=1:10
cmd = ['filename ',num2str(k)];
To pass a MATLAB variable to a program as input, you must first convert it to a character vector.

Run Standalone Applications that Use Arguments

You call a standalone application that uses arguments from MATLAB with any of the following commands:


  • DOS

  • UNIX

  • !

To pass the contents of a MATLAB variable to the program as an input, the variable must first be converted to a character vector. For example:


Specify the entire command to run the application as a character vector (including input arguments). For example, passing the numbers and letters 1 2 3 a b c could be executed using the SYSTEM command, as follows:

system('filename 1 2 3 a b c')

Using the ! (Bang) Operator

You can also use the ! (bang) operator, from within MATLAB, as follows:

!filename 1 2 3 a b c

When you use the ! (bang) operator, the remainder of the input line is interpreted as the SYSTEM command, so it is not possible to use MATLAB variables.

Using Windows

To run a standalone application by double-clicking it, you create a batch file that calls the standalone application with the specified input arguments. For example:

 rem This is main.bat file which calls 
 rem filename.exe with input parameters

 filename "[1 2 3]" "[4 5 6]"
 @echo off

The last two lines of code in main.bat are added so that the window displaying your output stays open until you press a key.

Once you save this file, you run your code with the arguments specified above by double clicking the icon for main.bat.

Using a MATLAB File You Plan to Deploy

When running MATLAB files that use arguments that you also plan to deploy with MATLAB Compiler, keep the following in mind:

  • The input arguments you pass to your executable from a system prompt are received as character vector input. Thus, if you expect the data in a different format (for example, double), you must first convert the character vector input to the required format in your MATLAB code. For example, you can use STR2NUM to convert the character vector input to numerical data.

  • You cannot return values from your standalone application to the user. The only way to return values from compiled code is to either display it on the screen or store it in a file.

    In order to have data displayed back to the screen, do one of the following:

    • Do not use semicolons to suppress commands that yield your return data.

    • Use the DISP command to display the variable value, then redirect the output to other applications using redirects (the > operator) or pipes (||) on non-Windows systems.

Display Data to Screen Using MATLAB File

Here are two ways to use a MATLAB file to take input arguments and display data to the screen:

Method 1

function [x,y]=foo(z);

if ischar(z)

Method 2

function [x,y]=foo(z);

if isdeployed