Can Fuzzy Logic Toolbox output words?

3 ビュー (過去 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 Center および File ExchangeFuzzy Logic in Simulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by