How to generate code of Machine Learning functions for real-time application?

3 visualizzazioni (ultimi 30 giorni)
Good morning,
I integrated a machine learning model developed with the classification learner application by matlab into an existing simulink model to make predictions taking some inputs calculated by the simulink model itself. I managed to do that using the "interpreted matlab function" block and calling a matlab function from it which includes the code to make prediction with the trained classification model. This allowed to compile and run the simulink model, but the issue is that the "interpreted matlab function" block does not support code generation, which is needed for my application since I want to build the model for the MicroAutoBox II (so with a system target file rti1401.tlc). So I replaced it with a simple matlab function block (which should be suitable for code generation) and then generated a .mex file of the function previously called in the "interpreted matlab function" block which includes the instructions to make prediction with the classification model. The Simulink model is still compiling and running, but if I try to build the model I get the following error:
"The extrinsic function 'FaultClass_CodeGen_mex' is not available for standalone code generation. It must be eliminated for stand-alone code to be generated. It could not be eliminated because its outputs appear to influence the calling function. Fix this error by not using 'FaultClass_CodeGen_mex' or by ensuring that its outputs are unused."
where FaultClass_CodeGen_mex is the mex file mentioned above.
I've tried different approaches suggested by other users on the web, but I could not be able to solve the problem. Is there an alternative way to do that? Or maybe, could it be an issue related to a too old version of the software?
Thank you for the support.

Risposte (1)

Drew
Drew il 26 Set 2023
Native Simulink blocks for model prediction have been developed, with more being added release by release. These support code generation. Below is an image from the doc page listed above, showing a list of available classification predict blocks at this time, and the release in which they were added:
If this answer helps you, please remember to accept the answer.

Categorie

Scopri di più su Get Started with Statistics and Machine Learning Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by