top of page
Search

# How to use Fuzzy Logic Toolbox in MATLAB

How to use Fuzzy Logic Toolbox in MATLAB

Introduction to Fuzzy Logic Toolbox

Fuzzy logic is a computational approach that handles reasoning that is approximate rather than fixed and exact. In MATLAB, the Fuzzy Logic Toolbox provides an environment for building and simulating fuzzy inference systems.

Defining Fuzzy Rules

Next, we need to establish the rules that link the input variables to the output variable. These rules determine how the tip is calculated based on the service and quality ratings.

1. Open the Rule Editor in the Fuzzy Logic Designer.

• If service is Low and quality is Low, then tip is Low.

• If service is Low and quality is Medium, then tip is Low.

• If service is Low and quality is High, then tip is Medium.

• If service is Medium and quality is Low, then tip is Low.

• If service is Medium and quality is Medium, then tip is Medium.

• If service is Medium and quality is High, then tip is Medium.

• If service is High and quality is Low, then tip is Low.

• If service is High and quality is Medium, then tip is Medium.

• If service is High and quality is High, then tip is High.

These rules define the relationship between service, quality, and the resulting tip.

## Simulating the Fuzzy Inference System

With the inputs, outputs, and rules defined, we can now simulate the system:

1. In the Rule Viewer, adjust the input values for service and quality to see how the tip changes.

2. Save the fuzzy inference system by exporting it to a .fisÂ file.

## Using the Fuzzy Logic System in Simulink

To integrate the fuzzy logic system into a Simulink model:

2. Import the .fisÂ file into the block.

3. Connect the inputs (service and quality) to the Fuzzy Logic Controller block.

4. Connect the output (tip) to a display or any other block to visualize the result.

## Example Simulation

Let's consider an example where the service rating is 1 (excellent) and the quality rating is 0.5 (average):

1. Set the input values in Simulink and run the simulation.

2. Observe the output tip, which should be around 0.7 (70% of the maximum possible tip).

Adjust the input values and rerun the simulation to see how the tip changes based on different service and quality ratings.