Can Fuzzy Logic Toolbox output words?

조회 수: 5 (최근 30일)
Nick Kelly
Nick Kelly 2016년 1월 14일
답변: Shubham 2024년 8월 29일
I have a simple .fis that outputs values between -3 and 3. There are three distinct categories within -3 and 3, meaning between -3 and -1 represents one category, -1 to 1 another, and 1 to 3 the last one. The fuzzy operator outputs numbers, which is what I expected it to do, but when looking at the numbers I'm having to convert in my head which category it is. Not that big of a deal, I know, but is still a minor inconvenience.
So my question is, can I have the fuzzy operator output words instead of numbers? If not, how do I make the matrix that the fuzzy operator is outputting into a specific matrix that says the name of my categories?
  댓글 수: 2
Olivia Milton-thompson
Olivia Milton-thompson 2018년 6월 4일
Hi Nick, I understand you published this a while ago but I've got the same question as you, and I was wondering if you got a solution in the end?
Thanks :)
Nick Kelly
Nick Kelly 2018년 6월 5일
figure(1)
Labels = {'High' 'Mid' 'Low'}; %creates Y-axis cell
plot(T, Data)
set(gca, 'YTick', -1:1, 'YTickLabel', Labels); % makes Y-axis Labels
xlabel('Time(s)'); ylabel('Position');
This is what worked for what I needed.

댓글을 달려면 로그인하십시오.

답변 (1개)

Shubham
Shubham 2024년 8월 29일
Hi Nick,
In MATLAB, if you're working with a Fuzzy Inference System (FIS) and want to map numerical outputs to categorical labels, you can achieve this by post-processing the output. While the FIS itself will output numerical values, you can write a simple script to convert these numbers into corresponding category names.
Here’s how you can do that:
  1. Create a function or script that maps the output values to category names.
  2. Use this mapping function to convert the numerical output to the desired labels.
Here’s a sample MATLAB script to illustrate this:
% Define the categories and their corresponding ranges
categories = {'Low', 'Medium', 'High'};
category_ranges = [-3, -1; -1, 1; 1, 3];
% Example output from the FIS
fis_output = [-2.5, 0.5, 2.2, -1.5, 1.5];
% Function to map numerical output to category names
function category_name = mapToCategory(value, categories, category_ranges)
for i = 1:length(categories)
if value >= category_ranges(i, 1) && value <= category_ranges(i, 2)
category_name = categories{i};
return;
end
end
category_name = 'Unknown'; % If the value doesn't fit any category
end
% Convert the FIS outputs to category names
category_labels = arrayfun(@(x) mapToCategory(x, categories, category_ranges), fis_output, 'UniformOutput', false);
% Display the results
disp('FIS Outputs and their corresponding categories:');
for i = 1:length(fis_output)
fprintf('Output: %.2f -> Category: %s\n', fis_output(i), category_labels{i});
end
Explanation:
  • You define the categories and their corresponding numerical ranges in the categories and category_ranges arrays.
  • The mapToCategory function checks which range the output value falls into and returns the corresponding category name.
  • The arrayfun function applies the mapToCategory function to each element of the fis_output array, converting all numerical outputs to category names.
This approach allows you to maintain a clear separation between numerical processing and categorical interpretation, making it easier to manage and update categories as needed.

카테고리

Help CenterFile Exchange에서 Fuzzy Logic in Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by