I have been provided with two data sets, crisp and fuzzy sets to create a graph. I am new to this and could really use your help how to add in the new data to change graphs

27 visualizzazioni (ultimi 30 giorni)
I have been provided with two data sets, crisp and fuzzy sets to create a graph. I am new to this and could really use your help how to add in the new data to change graphs
Question that needs answering:
Consider the following scale for levels of pain:
0: No Pain
1-3: Mild Pain
4-6: Moderate Pain
7-9: Severe Pain
10: Worst Possible Pain
Create two graphs, one with the crisp sets and another with the fuzzy sets for this scale. You can use any digital tool to draw your graph, including MATLAB, or you can draw it on paper and add a picture of it to your assignment.
% first crisp set:
% Define the range of the Glasgow Coma Scale
x = 3:0.1:15;
% Define the parameters for the trapezoidal membership functions
severe_params = [3, 3, 8, 8];
moderate_params = [9, 9, 12, 12];
mild_params = [13, 13, 15, 15];
% Calculate the membership values for each set
severe_injury = trapmf(x, severe_params);
moderate_injury = trapmf(x, moderate_params);
mild_injury = trapmf(x, mild_params);
% Plot the membership functions
figure;
plot(x, severe_injury, 'r', 'LineWidth', 2, 'DisplayName', 'Severe Injury');
hold on;
plot(x, moderate_injury, 'g', 'LineWidth', 2, 'DisplayName', 'Moderate Injury');
plot(x, mild_injury, 'b', 'LineWidth', 2, 'DisplayName', 'Mild Injury');
% Add labels and legend
xlabel('Glasgow Coma Scale');
ylabel('Membership');
title('Membership Functions for Glasgow Coma Scale');
legend('Location', 'Northwest');
grid on;
% Set axis limits
axis([3 15 0 1]);
% Display the graph
hold off;
% Fuzzy set:
% Define the range of the Glasgow Coma Scale
x = 3:0.1:15;
% Define the parameters for the triangular membership functions
severe_params = [3, 5, 8];
moderate_params = [7, 10, 13];
mild_params = [11, 14, 15];
% Calculate the membership values for each set
severe_injury = trimf(x, severe_params);
moderate_injury = trimf(x, moderate_params);
mild_injury = trimf(x, mild_params);
% Plot the membership functions
figure;
plot(x, severe_injury, 'r', 'LineWidth', 2, 'DisplayName', 'Severe Injury');
hold on;
plot(x, moderate_injury, 'g', 'LineWidth', 2, 'DisplayName', 'Moderate Injury');
plot(x, mild_injury, 'b', 'LineWidth', 2, 'DisplayName', 'Mild Injury');
% Add labels and legend
xlabel('Glasgow Coma Scale');
ylabel('Membership');
title('Fuzzy Sets for Glasgow Coma Scale');
legend('Location', 'Northwest');
grid on;
% Set axis limits
axis([3 15 0 1]);
% Display the graph
hold off;
Many thanks for your help in advance

Risposta accettata

Taylor
Taylor il 14 Nov 2024 alle 14:24
You can store the line properties (including the underlying data) from the plot command as shown in this example. Then you can edit the XData and YData and the plot with update with the new data.
  3 Commenti
Taylor
Taylor il 14 Nov 2024 alle 15:25
If I'm understanding the question correctly, I think this is what you're looking for. The first plot show clear boundaries for membership to groups of different injury levels and the second shows fuzzy (i.e, slightly overlapping) boundaries.
% first crisp set:
% Define the range of the Glasgow Coma Scale
x = 0:0.1:15;
% Define the parameters for the trapezoidal membership functions
no_params = [0, 0, 2, 2];
mild_params = [3, 3, 8, 8];
moderate_params = [9, 9, 12, 12];
severe_params = [13, 13, 15, 15];
% Calculate the membership values for each set
no_injury = trapmf(x, no_params);
mild_injury = trapmf(x, mild_params);
moderate_injury = trapmf(x, moderate_params);
severe_injury = trapmf(x, severe_params);
% Plot the membership functions
figure;
plot(x, no_injury, 'k', 'LineWidth', 2, 'DisplayName', 'No Injury');
hold on;
plot(x, mild_injury, 'b', 'LineWidth', 2, 'DisplayName', 'Mild Injury');
plot(x, moderate_injury, 'g', 'LineWidth', 2, 'DisplayName', 'Moderate Injury');
plot(x, severe_injury, 'r', 'LineWidth', 2, 'DisplayName', 'Severe Injury');
% Add labels and legend
xlabel('Glasgow Coma Scale');
ylabel('Membership');
title('Membership Functions for Glasgow Coma Scale');
legend('Location', 'Northwest');
grid on;
% Set axis limits
axis([0 15 0 1]);
% Display the graph
hold off;
% Fuzzy set:
% Define the range of the Glasgow Coma Scale
x = 0:0.1:15;
% Define the parameters for the triangular membership functions
no_params = [0, 1, 4];
mild_params = [3, 5, 8];
moderate_params = [7, 10, 13];
severe_params = [11, 14, 15];
% Calculate the membership values for each set
no_injury = trimf(x, no_params);
severe_injury = trimf(x, severe_params);
moderate_injury = trimf(x, moderate_params);
mild_injury = trimf(x, mild_params);
% Plot the membership functions
figure;
plot(x, no_injury, 'k', 'LineWidth', 2, 'DisplayName', 'No Injury');
hold on;
plot(x, severe_injury, 'r', 'LineWidth', 2, 'DisplayName', 'Severe Injury');
plot(x, moderate_injury, 'g', 'LineWidth', 2, 'DisplayName', 'Moderate Injury');
plot(x, mild_injury, 'b', 'LineWidth', 2, 'DisplayName', 'Mild Injury');
% Add labels and legend
xlabel('Glasgow Coma Scale');
ylabel('Membership');
title('Fuzzy Sets for Glasgow Coma Scale');
legend('Location', 'Northwest');
grid on;
% Set axis limits
axis([0 15 0 1]);
% Display the graph
hold off;

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by