0

After designing my state machine using matlab state flow and generating its C code using code generation, I could easily run it in my application in visual studio. However, after a while I needed to call specific functions at each state transitions. And it is important to mention that each transition can have its own functions.

For those who are pro in both c and matlab, I think this issue can be solved if there is a way that matlab code generation, generates __weak callback functions for each state transition. In that case, I can fill the body of these callback functions and whenever state transitions happen, generated code will call them and my methods will be executed. I could not find any way to force matlab to generate these callback functions. Is this available in matlab or are there any other solutions to overcome this issue?

Another solution is to call the name of my functions in matlab state flow at each transition and let matlab know that these functions will be defined later in my application, so that it won't give me errors for generating the c code. However I could not figure out this one too!

siii fsxa
  • 45
  • 5
  • I would be surprised if MATLAB had any built-in mechanism that generated C code relying on a keyword `__weak`, as the C language does not define any such thing. The leading double underscores put "__weak" in the realm of implementation-specific extensions. More generally, C does not have a concept of weak linkage. – John Bollinger Feb 21 '23 at 12:55
  • It's all about attributes in c and it is as easy as typing a simple text :D – siii fsxa Feb 21 '23 at 12:57
  • Ease is irrelevant. I do not expect general-purpose code generators to emit code that depends on implementation-specific language extensions. And I do not expect MATLAB to make an exception for something like `__weak`, as it does not appear to serve MATLAB's primary purposes in providing for code generation. – John Bollinger Feb 21 '23 at 13:02
  • Well, forget about weak attribute! Matlab code generator can use a user defined callback that will be defined in the application! How about that? Will it solve your problem with "implementation specific" part of the solution? I want a solution so that matlab can give me access to the internal parts of the state machine! You can suggest one, then good for you (and me too :D) – siii fsxa Feb 22 '23 at 09:55

0 Answers0