Pass input arugments in .exe file generated by Matlab coder

3 次查看(过去 30 天)
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

采纳的回答

dpb
dpb 2023-9-11
<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 个评论
Wladimir Plotnikov
Wladimir Plotnikov 2023-9-21
Hey there,
I just wanted to say that I could manage it to store my relevant data by using fopen and fwrite while creating a .bin file.
Then, I've written a .m file which opens and plot my data from the .bin file.
It perfectly works, thanks a lot for your help!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

产品


版本

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by