MATLAB: How to generate code from the system I’ve designed in the fuzzy logic designer

codedesignerfuzzyFuzzy Logic Toolboxgenerationinferencelogicsimulink codersystem

I have created a system using the fuzzy logic designer. How can I generate code from this system?

Best Answer

To generate code for your fuzzy logic system, you will need to bring the logic into a Simulink system. This process generally follows these steps:
  1. Create your fuzzy system using the fuzzy system designer. Once complete, <https://www.mathworks.com/help/fuzzy/building-systems-with-fuzzy-logic-toolbox-software.html#FP686 export the system> to the MATLAB workspace by selecting File > Export > To Workspace. 
  2. Bring your exported fuzzy system variable into Simulink using a "<https://www.mathworks.com/help/fuzzy/fuzzylogiccontroller.html Fuzzy Logic Controller>" block. <https://www.mathworks.com/help/fuzzy/generate-code-for-fuzzy-system-using-simulink-coder.html This PID control example> demonstrates this. If you open the model from this example, you will notice a structure named "FIS" in the MATLAB workspace. This is a structure that had previously been exported from the fuzzy logic designer. "FIS" was then brought into Simulink using a fuzzy logic controller block named "Fuzzy Inference System" within the subsystem "Fuzzy PID". In the fuzzy logic controller block, specify the name of your fuzzy logic structure (here, it's "FIS"). From here, you can simulate the model and see how the fuzzy logic controller works, given specific inputs.
  3. When you have completed your model and are ready to generate code for the model, click on the "Build Model" button (or Ctrl-B). When the build process has completed successfully, you will see a new folder in your current folder named "fuzzyPID_grt_rtw". This folder includes all the generated source and header code files your model. Refer to the previously-linked example documentation to read more about the specific files generated.
Note that you will need a Simulink Coder license to generate code for your fuzzy logic system.
Related Question