I'm trying to compile a Matlab code using codegen and making an executable. The thing is that after compilation, I can't seem to successfully call the app from matlab along with the relevant input. I'll explain:
To make things simple, let's assume that the purpose of my program is to create a '.txt' file named 'my_text.txt' and print an input string inside, like so:
function PrintMyString(input_str) %#codegen
fid = fopen('my_text.txt','w'); fprintf(fid,'My input string is: %s',input_str); fclose(fid);end
Now, I tried to compile the code above using the following script:
str = 'pre_defining_the_input_variable_by_example';codegen -config config_obj PrintMyString -args {str}
when config_obj is the code generation configuration defined somewhere earlier.
The compilation was successful, but as I mentioned before, when I tried to activate the program it didn't go as planned. I tried various options for calling, such as:
system(['PrintMyString.exe ',str]);
The text file was created, but no input string was printed (all that appeared was the line "My input string is: ").
I also tried adding a main function that calls the original PrintMyString function, like so:
function main() %#codegen str = 'some_string'; PrintMyString(str);end
I compiled it like that:
str = 'pre_defining_the_input_variable_by_example';codegen -config config_obj main PrintMyString -args {str}
And that worked, but obviously it doesn't help because the input string has to be sent to the program from outside.
Any ideas? What am I doing wrong?
Best Answer