Can we create C code from m script (not from m function)??
Mostrar comentarios más antiguos
Actually I have a m script not m function which I want to to generate c/cpp code,can we do if yes how??
5 comentarios
Rik
el 20 de Sept. de 2018
Why not make it a function?
sanjeev kumar
el 23 de Sept. de 2018
Rik
el 23 de Sept. de 2018
Does it though? You can just put function at the top and end at the bottom. Sure, that would not be following best practice, but a long script doesn't either.
Adam
el 24 de Sept. de 2018
Well, if it takes a lot of effort that implies there are a lot of variables that are just expected to already exist in the workspace when it runs and if that is the case then clearly you can't expect to have it converted to C/C++ code, as Jan says, C/C++ code needs an entry point. If you don't have lots of hidden assumptions on variable that need to already exist then, as Rik says, it is trivial to add one line to the top of your script. You don't even need the end at the bottom if you are really averse to the extra work!
sanjeev kumar
el 24 de Sept. de 2018
Respuestas (2)
It is impossible. A C/CPP code must receive some inputs and provide outputs, but scripts do not have a defined input/output interface. In consequence only functions can be converted to C-functions. There are no "C-scripts".
Because a long script need lots of extra effort to make it function :)
Writing "long scripts" is a general mistake and it impedes writing and debugging the code - as well as converting it to C.
2 comentarios
Stephen23
el 24 de Sept. de 2018
+1 correct and useful advice.
sanjeev kumar
el 24 de Sept. de 2018
Walter Roberson
el 24 de Sept. de 2018
0 votos
MATLAB Coder refuses to use a script as the entry point.
For a number of years, MATLAB Compiler also refused to compile scripts as the entry point. I saw hints that might have changed a few years ago, with it effectively just tossing on a function line that it generated, but I am not certain of this.
For reasons that others discussed, compiled code really should have a function header to define the interface.
If the situation happened to be that you had a very long script and the time to parse it for interactive execution was becoming a problem, then an option would be to pcode it as pcode pre-parses. But in such a case the code would almost certainly be better rewritten. And this case would have little relevance to the MATLAB Coder use case.
Categorías
Más información sobre MATLAB Coder en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!