How do I pass arguments into and out of my standalone executable?
306 views (last 30 days)
Show older comments
I want to be able to pass input and output arguments to my standalone application when I bang out to the DOS shell from MATLAB.
Accepted Answer
MathWorks Support Team
on 3 Nov 2021
Edited: MathWorks Support Team
on 4 Nov 2021
Please refer the below documentation link:
0 Comments
More Answers (4)
Antti
on 26 Jan 2018
Note that in R2017b (and possibly beyond) on Windows 10, no output is printed on the Windows command prompt unless you uncheck "Do not display the Windows command shell (console) for execution" under "Additional runtime settings" in the Application Compiler tool of MATLAB Compiler.
0 Comments
Iaroslav Linder
on 5 Nov 2018
Edited: Iaroslav Linder
on 5 Nov 2018
Finally found a solution how to input and output variables in generated executables. Here is the example (Name the script main.m)
function out=main()
num=0; %this converts to double
if coder.target('MATLAB')
num=input("Enter number");
else
coder.ceval('scanf','%lf',coder.ref(num)); % not '%f'
end
fprintf(1,'The squared value is %f\n',sqrt(double(num)));
out=int32(0);
end
2 Comments
Iaroslav Linder
on 5 Nov 2018
it is even possible to let executable file accept command line arguments. But it requires a little trick to set the type of the second argument as the structure (struct 1 x:50) of type (char*)

function out=main(argc, argv)
fprintf(1,"Number of args %d\n",argc)
X_sum=complex(0);
for i=1:argc
tmp=char(zeros(1,100));
coder.ceval("strcpy",coder.ref(tmp),argv(i));
X = str2double(tmp);
if (imag(X)~=0||real(X)~=0)
fprintf(1,'%lf \n',X)
X_sum=X_sum+X;
end
end
fprintf(1,'Summ %lf \n',X_sum)
out=int32(0);
end
Steve Lim
on 13 Dec 2016
The examples show how to specify the input parameters to launch an application (exe). Within the application, what's the MATLAB source code look like to get the input parameter strings?
Thank you.
1 Comment
Walter Roberson
on 13 Dec 2016
Depending on whether you are expecting scalars or not, str2double() or use some sscanf() or even textscan() on the string. (You can pass a string as the first parameter to textscan to have it read, instead of passing a file identifier there.)
Ewen Chan
on 17 May 2018
Sorry for resurrecting a super old thread, but I have a question about this:
So in the script that I have now, at the start of it, I have declared some variables and assigned them values.
e.g.:
c0 = 3;
c1 = 100;
c2 = 500;
pi = 0.1;
p = 0.05;
N = 650;
e1 = 0.001;
e2 = 0.001;
If I want to create a standalone application, so that I can vary the numbers for those variables, how would I go about doing that?
Do I use the Application Compiler?
And if so, how do I go about doing that? This is my first attempt at a) trying to compile a standalone application and b) trying to pass input arguments that will change the variables that is currently at the top of my script/code.
Any help would be greatly appreciated.
Thank you.
3 Comments
Kristen Lancaster
on 11 Feb 2019
Did you get it working? Could anyone provide input on my attempts to use command line arguments with a standalone created with MATLAB Coder?
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!