Pass input arugments in .exe file generated by Matlab coder
3 views (last 30 days)
Show older comments
Hello everybody,
it's the first time I'm working with the Matlab coder.
My aim is to generate an .exe file, where it's possible to pass arguments in order to run the program.
Up to now, I could actually manage to generate an .exe file which runs perfectly.
My issue is to pass arguments in this .exe file, since it's still a static program running every run with the same parameter values.
Assuming my generated file has the name "Test.exe" and one input is the parameter "dim" (so in Matlab it's Test(dim)), I'm running the program with "system('Test.exe dim')".
In order to check the value of the input "dim", I'm using fprintf for the console.
Further on, to enable the generation of the .exe, I've used:
if(isempty(dim)==0)
dim = 1;
end
Unfortunately, it doesn't matter which value dim has, it's always empty "[ ]".
For better illustrations, my example code:
Test(dim)
fprintf("The parameter dim has the value: %1.0f", dim)
if(isempty(dim)==0)
dim = 1;
end
end
0 Comments
Accepted Answer
dpb
on 11 Sep 2023
<You must modify a main.c> function to read/use an argument list when creating a standalone executable; it doesn't happen by default (as you've discovered).
Follow the above link in detail, it progresses through the steps of showing how/where the default main.c file is created and then how to modify a copy to include the things your application needs....eventually it gets to illustrating the use of the C command line argument functions to (in the example) read a specific input file instead of using the builtin default image the example starts with.
Follow the bread crumbs trail through the woods and, like Hansel and Gretel, you'll eventually get back from the witch's house to the land of Oz...or is it Kansas?
9 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!