How can I generate code from the system I've designed in the fuzzy logic designer?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
Hello everyone :)
I am currently facing a problem to generate the coding from fuzzy logic designer. . I'm using FIS mamdani type-1, after inserted all the data such as input, rules, and output i don't know how to generate the coding. How can I generate code from this system? Can someone help me?
Thank you in advance.
Accepted Answer
I understand that you want to generate the code from fuzzy logic designer,
To generate code for a fuzzy logic system in MATLAB, you'll need to integrate it into a Simulink model.
Here's a detailed explanation of the process,
- Design your fuzzy logic system using the “Fuzzy Logic Designer tool”. Once you've defined your input variables, membership functions, fuzzy rules, and output variables, export the system to the MATLAB workspace. You can do this by selecting "File" > "Export" > "To Workspace".
- Bring your exported fuzzy system variable into Simulink using a "Fuzzy Logic Controller" block. This block allows you to incorporate fuzzy logic functionality into your Simulink model. You can find this block in the Simulink Library Browser.
- In the Fuzzy Logic Controller block, specify the name of your fuzzy logic structure (e.g., "FIS"). This structure contains all the fuzzy logic rules and parameters that you defined earlier in the Fuzzy Logic Designer. You can customize the settings of the Fuzzy Logic Controller block to suit your specific application.
- Once the fuzzy logic controller is integrated into your Simulink model, you can simulate the model to observe how the fuzzy logic system behaves with specific inputs. This allows you to validate the functionality of your fuzzy logic system within the context of your overall system design.
- When your Simulink model is complete and you're ready to generate code, click on the "Build Model" button (or press Ctrl+B). This initiates the code generation process. Upon successful completion of the build process, you'll find a new folder named "yourModel_grt_rtw" in your current directory. This folder contains all the generated source and header code files for your model.
Note: It's important to note that you'll need a Simulink Coder license to generate code for your fuzzy logic system.
I have attempted to create a Fuzzy Inference System (FIS) model from my end as well. Please find the associated files attached below for your reference,
You can find the model below in the attachements,
The below is the diagnostic viewer window once building is done,

The below are the code files generated after building the model,

Refer to the documentation below to learn more about the specific files generated during the code generation process,
Hope this helps!
6 Comments
Nurul Ainina
on 5 May 2024
How to bring my exported fuzzy system variable into Simulink using a "Fuzzy Logic Controller" block? i already drag the fuzzy logic controller but the block is error?
Sam Chak
on 5 May 2024
Hi Nina, please show how you inserted the Fuzzy Logic Controller block in the Simulink model so that Sanju can help you with proper advice.
You can also provide additional images such as the fuzzy tree, fuzzy membership functions, fuzzy rules and fuzzy surfaces.
Nurul Ainina
on 5 May 2024
Edited: Nurul Ainina
on 6 May 2024
Hi, I already exported my fuzzy system to the Fuzzy logic controller block in simulink. How to generate the code for my fuzzy system? I need the code to insert to my GUI. For example, when I click the calculate button the value of "AP index (material)" will be appear to my GUI. Here is my FIS and simulink:
I ready need someone help, thankyou in advance :)


Sam Chak
on 6 May 2024
Using the "@" symbol is an effective way to address someone in a post. It notifies them and ensures they are made aware of your feedback or update. Since you accepted the solution for code generation provided by @Sanju, it generally implies that your problem has been resolved.
Have you had the opportunity to test the approach outlined in the Answer before accepting the solution?
Sanju
on 6 May 2024
Regarding the code generation, please refer to the answer given above, also if you face any issue please share the complete error message and the model you're working on so that I can check from my end.
More Answers (0)
Categories
Find more on Fuzzy Logic in Simulink in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)