How to build the app in order to plot the fuzzy membership function aligned with the value in slider
1 次查看(过去 30 天)
显示 更早的评论
Junghwan
2023-2-7
Hello, everyone.
I'm struggling to build the app and UIAxes in order to plot the fuzzy membership function graph aligned with the value in slider.
I have no idea how to facilitate the UIAxes to display the fuzzy membership function graph when I adjust the value in sliders.
I manage to make the callback function numeric edit field aligned with slider.
I'd like to make app as I learned in Mathworks channel as following;
I'm looking forward to getting precious help and any feedback from the community.
6 个评论
Adam Danz
2023-2-7
> I have no idea how to facilitate the UIAxes to display the fuzzy membership function graph
Most readers, including me, have not seen this video. What problem are you having with the UIAxes and how are you producing the fuzzy membership graph?
Junghwan
2023-2-7
First of all, thanks for your feedback and prompt response.
I make a fuzzy logic inference system as following;
[System]
Name='Fuzzy'
Type='mamdani'
Version=2.0
NumInputs=4
NumOutputs=1
NumRules=81
AndMethod='min'
OrMethod='max'
ImpMethod='min'
AggMethod='max'
DefuzzMethod='centroid'
[Input1]
Name='General'
Range=[0 10]
NumMFs=3
MF1='low':'gaussmf',[1.5 0]
MF2='medium':'gaussmf',[1.5 5]
MF3='high':'gaussmf',[1.5 10]
figure(1)
subplot(2,1,1)
plotMF1(fis, 'Input1', 1), grid on, title('Input 1: Amount of Dirt')
subplot(2,1,2)
plotMF2(fis, 'input', 2), grid on, title('Input 2: Amount of Grease')
[Input2]
Name='Fuel_receiving_and_refueling_area'
Range=[0 10]
NumMFs=3
MF1='low':'gaussmf',[1.5 0]
MF2='medium':'gaussmf',[1.5 5]
MF3='high':'gaussmf',[1.5 10]
[Input3]
Name='Reactor_area'
Range=[0 10]
NumMFs=3
MF1='low':'gaussmf',[1.5 0]
MF2='medium':'gaussmf',[1.5 5]
MF3='high':'gaussmf',[1.5 10]
[Input4]
Name='Spent_fuel_pool_area'
Range=[0 10]
NumMFs=3
MF1='low':'gaussmf',[1.5 0]
MF2='medium':'gaussmf',[1.5 5]
MF3='high':'gaussmf',[1.5 10]
[Output1]
Name='Safeguardability'
Range=[0 10]
NumMFs=5
MF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
2 3 2 3, 4 (1) : 2
2 3 3 1, 3 (1) : 2
2 3 3 2, 4 (1) : 2
2 3 3 3, 4 (1) : 2
3 1 1 1, 2 (1) : 2
3 1 1 2, 3 (1) : 2
3 1 1 3, 3 (1) : 2
3 1 2 1, 3 (1) : 2
3 1 2 2, 3 (1) : 2
3 1 2 3, 3 (1) : 2
3 1 3 1, 3 (1) : 2
3 1 3 2, 3 (1) : 2
3 1 3 3, 4 (1) : 2
3 2 1 1, 3 (1) : 2
3 2 1 2, 3 (1) : 2
3 2 1 3, 3 (1) : 2
3 2 2 1, 3 (1) : 2
3 2 2 2, 3 (1) : 2
3 2 2 3, 4 (1) : 2
3 2 3 1, 3 (1) : 2
3 2 3 2, 4 (1) : 2
3 2 3 3, 4 (1) : 2
3 3 1 1, 3 (1) : 2
3 3 1 2, 3 (1) : 2
3 3 1 3, 4 (1) : 2
3 3 2 1, 3 (1) : 2
3 3 2 2, 4 (1) : 2
3 3 2 3, 4 (1) : 2
3 3 3 1, 4 (1) : 2
3 3 3 2, 4 (1) : 2
3 3 3 3, 5 (1) : 2
Also, I'm still making an application through app designer.
So far, I managed to make callbackfunction aligned with the slider and the numeric figures have been applied as inputs in FIS. The assessed figure has been calculated in edit field highlighted yellow color when I push the "Process" button.
What I'm trying to do is to make a callbackfunction in order to display(plot) the calculated membership function graph in UIAxes when I press the "Process" button such as an example in the below.
So far, I'm struggling to make a callbackfunction into the draft version of code as following;
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
NuclearSafeguardsQuantitativeAssessmentforSMRLabel matlab.ui.control.Label
OutputPanel matlab.ui.container.Panel
SafeguardabilityEditField matlab.ui.control.NumericEditField
SafeguardabilityEditFieldLabel matlab.ui.control.Label
ProcessButton matlab.ui.control.Button
UIAxes matlab.ui.control.UIAxes
InputPanel matlab.ui.container.Panel
Spent_fuel_pool_areaSlider matlab.ui.control.Slider
Spent_fuel_pool_areaSliderLabel matlab.ui.control.Label
Reactor_areaSlider matlab.ui.control.Slider
Reactor_areaSliderLabel matlab.ui.control.Label
Fuel_receiving_and_refueling_areaSlider matlab.ui.control.Slider
Fuel_receiving_and_refueling_areaSliderLabel matlab.ui.control.Label
EditField_4 matlab.ui.control.NumericEditField
EditField_3 matlab.ui.control.NumericEditField
EditField_2 matlab.ui.control.NumericEditField
EditField matlab.ui.control.NumericEditField
GeneralSlider matlab.ui.control.Slider
GeneralSliderLabel matlab.ui.control.Label
InformationPanel matlab.ui.container.Panel
LWRtypeofSMRSmallModularReactorCheckBox matlab.ui.control.CheckBox
ReactorNameEditField matlab.ui.control.EditField
ReactorNameEditFieldLabel matlab.ui.control.Label
end
% Callbacks that handle component events
methods (Access = private)
% Value changed function: GeneralSlider
function GeneralSliderValueChanged(app, event)
value = app.GeneralSlider.Value;
app.EditField.Value = value;
end
% Value changed function: Fuel_receiving_and_refueling_areaSlider
function Fuel_receiving_and_refueling_areaSliderValueChanged(app, event)
value = app.Fuel_receiving_and_refueling_areaSlider.Value;
app.EditField_2.Value = value;
end
% Value changed function: Reactor_areaSlider
function Reactor_areaSliderValueChanged(app, event)
value = app.Reactor_areaSlider.Value;
app.EditField_3.Value = value;
end
% Value changed function: Spent_fuel_pool_areaSlider
function Spent_fuel_pool_areaSliderValueChanged(app, event)
value = app.Spent_fuel_pool_areaSlider.Value;
app.EditField_4.Value = value;
end
% Button pushed function: ProcessButton
function ProcessButtonPushed(app, event)
General = app.EditField.Value;
Fuel_receiving_and_refueling_area = app.EditField_2.Value;
Reactor_area = app.EditField_3.Value;
Spent_fuel_pool_area = app.EditField_4.Value;
fis = readfis('Fuzzy');
output = evalfis(fis,[General Fuel_receiving_and_refueling_area Reactor_area Spent_fuel_pool_area]);
app.SafeguardabilityEditField.Value = output;
end
% Button down function: UIAxes
function UIAxesButtonDown(app, event)
gensurf(fis)
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 903 578];
app.UIFigure.Name = 'MATLAB App';
% Create InformationPanel
app.InformationPanel = uipanel(app.UIFigure);
app.InformationPanel.Title = 'Information';
app.InformationPanel.Position = [30 388 379 106];
% Create ReactorNameEditFieldLabel
app.ReactorNameEditFieldLabel = uilabel(app.InformationPanel);
app.ReactorNameEditFieldLabel.HorizontalAlignment = 'right';
app.ReactorNameEditFieldLabel.Position = [17 44 83 22];
app.ReactorNameEditFieldLabel.Text = 'Reactor Name';
% Create ReactorNameEditField
app.ReactorNameEditField = uieditfield(app.InformationPanel, 'text');
app.ReactorNameEditField.Position = [130 44 184 22];
% Create LWRtypeofSMRSmallModularReactorCheckBox
app.LWRtypeofSMRSmallModularReactorCheckBox = uicheckbox(app.InformationPanel);
app.LWRtypeofSMRSmallModularReactorCheckBox.Text = ' LWR type of SMR (Small Modular Reactor)';
app.LWRtypeofSMRSmallModularReactorCheckBox.Position = [22 12 294 22];
% Create InputPanel
app.InputPanel = uipanel(app.UIFigure);
app.InputPanel.Title = 'Input';
app.InputPanel.Position = [30 25 379 351];
% Create GeneralSliderLabel
app.GeneralSliderLabel = uilabel(app.InputPanel);
app.GeneralSliderLabel.HorizontalAlignment = 'right';
app.GeneralSliderLabel.Position = [15 299 48 22];
app.GeneralSliderLabel.Text = 'General';
% Create GeneralSlider
app.GeneralSlider = uislider(app.InputPanel);
app.GeneralSlider.Limits = [0 10];
app.GeneralSlider.ValueChangedFcn = createCallbackFcn(app, @GeneralSliderValueChanged, true);
app.GeneralSlider.Position = [138 290 209 3];
% Create EditField
app.EditField = uieditfield(app.InputPanel, 'numeric');
app.EditField.Position = [35 266 68 22];
% Create EditField_2
app.EditField_2 = uieditfield(app.InputPanel, 'numeric');
app.EditField_2.Position = [36 173 68 22];
% Create EditField_3
app.EditField_3 = uieditfield(app.InputPanel, 'numeric');
app.EditField_3.Position = [36 100 68 22];
% Create EditField_4
app.EditField_4 = uieditfield(app.InputPanel, 'numeric');
app.EditField_4.Position = [36 23 68 22];
% Create Fuel_receiving_and_refueling_areaSliderLabel
app.Fuel_receiving_and_refueling_areaSliderLabel = uilabel(app.InputPanel);
app.Fuel_receiving_and_refueling_areaSliderLabel.HorizontalAlignment = 'right';
app.Fuel_receiving_and_refueling_areaSliderLabel.Position = [13 216 195 22];
app.Fuel_receiving_and_refueling_areaSliderLabel.Text = 'Fuel_receiving_and_refueling_area';
% Create Fuel_receiving_and_refueling_areaSlider
app.Fuel_receiving_and_refueling_areaSlider = uislider(app.InputPanel);
app.Fuel_receiving_and_refueling_areaSlider.Limits = [0 10];
app.Fuel_receiving_and_refueling_areaSlider.ValueChangedFcn = createCallbackFcn(app, @Fuel_receiving_and_refueling_areaSliderValueChanged, true);
app.Fuel_receiving_and_refueling_areaSlider.Position = [137 196 209 3];
% Create Reactor_areaSliderLabel
app.Reactor_areaSliderLabel = uilabel(app.InputPanel);
app.Reactor_areaSliderLabel.HorizontalAlignment = 'right';
app.Reactor_areaSliderLabel.Position = [16 131 78 22];
app.Reactor_areaSliderLabel.Text = 'Reactor_area';
% Create Reactor_areaSlider
app.Reactor_areaSlider = uislider(app.InputPanel);
app.Reactor_areaSlider.Limits = [0 10];
app.Reactor_areaSlider.ValueChangedFcn = createCallbackFcn(app, @Reactor_areaSliderValueChanged, true);
app.Reactor_areaSlider.Position = [138 121 209 3];
% Create Spent_fuel_pool_areaSliderLabel
app.Spent_fuel_pool_areaSliderLabel = uilabel(app.InputPanel);
app.Spent_fuel_pool_areaSliderLabel.HorizontalAlignment = 'right';
app.Spent_fuel_pool_areaSliderLabel.Position = [15 54 123 22];
app.Spent_fuel_pool_areaSliderLabel.Text = 'Spent_fuel_pool_area';
% Create Spent_fuel_pool_areaSlider
app.Spent_fuel_pool_areaSlider = uislider(app.InputPanel);
app.Spent_fuel_pool_areaSlider.Limits = [0 10];
app.Spent_fuel_pool_areaSlider.ValueChangedFcn = createCallbackFcn(app, @Spent_fuel_pool_areaSliderValueChanged, true);
app.Spent_fuel_pool_areaSlider.Position = [139 44 209 3];
% Create OutputPanel
app.OutputPanel = uipanel(app.UIFigure);
app.OutputPanel.Title = 'Output';
app.OutputPanel.Position = [439 25 437 469];
% Create UIAxes
app.UIAxes = uiaxes(app.OutputPanel);
title(app.UIAxes, 'Title')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
zlabel(app.UIAxes, 'Z')
app.UIAxes.ButtonDownFcn = createCallbackFcn(app, @UIAxesButtonDown, true);
app.UIAxes.Position = [17 65 405 256];
% Create ProcessButton
app.ProcessButton = uibutton(app.OutputPanel, 'push');
app.ProcessButton.ButtonPushedFcn = createCallbackFcn(app, @ProcessButtonPushed, true);
app.ProcessButton.Position = [292 16 100 22];
app.ProcessButton.Text = 'Process';
% Create SafeguardabilityEditFieldLabel
app.SafeguardabilityEditFieldLabel = uilabel(app.OutputPanel);
app.SafeguardabilityEditFieldLabel.HorizontalAlignment = 'right';
app.SafeguardabilityEditFieldLabel.Position = [45 16 92 22];
app.SafeguardabilityEditFieldLabel.Text = 'Safeguardability';
% Create SafeguardabilityEditField
app.SafeguardabilityEditField = uieditfield(app.OutputPanel, 'numeric');
app.SafeguardabilityEditField.BackgroundColor = [1 1 0];
app.SafeguardabilityEditField.Position = [152 16 100 22];
% Create NuclearSafeguardsQuantitativeAssessmentforSMRLabel
app.NuclearSafeguardsQuantitativeAssessmentforSMRLabel = uilabel(app.UIFigure);
app.NuclearSafeguardsQuantitativeAssessmentforSMRLabel.HorizontalAlignment = 'center';
app.NuclearSafeguardsQuantitativeAssessmentforSMRLabel.FontSize = 24;
app.NuclearSafeguardsQuantitativeAssessmentforSMRLabel.FontWeight = 'bold';
app.NuclearSafeguardsQuantitativeAssessmentforSMRLabel.Position = [140 519 627 33];
app.NuclearSafeguardsQuantitativeAssessmentforSMRLabel.Text = 'Nuclear Safeguards Quantitative Assessment for SMR';
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = app1
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
Adam Danz
2023-2-7
I don't know what plotMF1 and plotMF2 are from the snippet below but I assume you are trying to work that into your app. Is that right?
figure(1)
subplot(2,1,1)
plotMF1(fis, 'Input1', 1), grid on, title('Input 1: Amount of Dirt')
subplot(2,1,2)
plotMF2(fis, 'input', 2), grid on, title('Input 2: Amount of Grease')
After creating a callback fuction for the SafeGuardability box (I assume this should trigger a plot update), update the plot within that callback function. Don't forget to specify the axis handle plot(app.UIAxes, __). No need to generate a new figure or call subplot .
Junghwan
2023-2-8
That's correct! That code was referred and quoted from other FIS example.
By following the feedback, I need to update the plot within not FIS but that callback function and specify the axis handle plot as following;
% Button pushed function: ProcessButton
function ProcessButtonPushed(app, event)
General = app.EditField.Value;
Fuel_receiving_and_refueling_area = app.EditField_2.Value;
Reactor_area = app.EditField_3.Value;
Spent_fuel_pool_area = app.EditField_4.Value;
fis = readfis('Fuzzy');
output = evalfis(fis,[General Fuel_receiving_and_refueling_area Reactor_area Spent_fuel_pool_area]);
app.SafeguardabilityEditField.Value = output;
% If I want to display membership functions of Inputs and Output... %
plotMF1(fis, 'Input1', 1), grid on, title('Input 1: General')
plotMF2(fis, 'Input1', 1), grid on, title('Input 1: General')
plotMF3(fis, 'Input1', 1), grid on, title('Input 1: General')
plotMF1(fis, 'Input2', 1), grid on, title('Input 2: Fuel_receiving_and_refueling_area')
plotMF2(fis, 'Input2', 1), grid on, title('Input 2: Fuel_receiving_and_refueling_area')
plotMF3(fis, 'Input2', 1), grid on, title('Input 2: Fuel_receiving_and_refueling_area')
plotMF1(fis, 'Input3', 1), grid on, title('Input 3: Reactor_area')
plotMF2(fis, 'Input3', 1), grid on, title('Input 3: Reactor_area')
plotMF3(fis, 'Input3', 1), grid on, title('Input 3: Reactor_area')
plotMF1(fis, 'Input4', 1), grid on, title('Input 4: Spent_fuel_pool_area')
plotMF2(fis, 'Input4', 1), grid on, title('Input 4: Spent_fuel_pool_area')
plotMF3(fis, 'Input4', 1), grid on, title('Input 4: Spent_fuel_pool_area')
plotMF1(fis, 'Output1', 1), grid on, title('Output 1: Safeguardability')
plotMF2(fis, 'Output1', 1), grid on, title('Output 1: Safeguardability')
plotMF3(fis, 'Output1', 1), grid on, title('Output 1: Safeguardability')
plotMF4(fis, 'Output1', 1), grid on, title('Output 1: Safeguardability')
plotMF5(fis, 'Output1', 1), grid on, title('Output 1: Safeguardability')
end
% Button down function: UIAxes
function UIAxesButtonDown(app, event)
% If I want to display the membership functions of Output on UIAxes...
x=1:0.5:10;
MF1='Very_low':'trimf',[-2.5 0 2.5]
MF2='Low':'trimf',[0 2.5 5]
MF3='Medium':'trimf',[2.5 5 7.5]
MF4='High':'trimf',[5 7.5 10]
MF5='Very_high':'trimf',[7.5 10 12.5]
plot(app.UIAxes,x,MF[1:5])
end
Am I correct to follow your valuable feedback?
FYI, the inputs and output have been established as following;
[Input1]
Name='General'
Range=[0 10]
NumMFs=3
MF1='low':'gaussmf',[1.5 0]
MF2='medium':'gaussmf',[1.5 5]
MF3='high':'gaussmf',[1.5 10]
[Input2]
Name='Fuel_receiving_and_refueling_area'
Range=[0 10]
NumMFs=3
MF1='low':'gaussmf',[1.5 0]
MF2='medium':'gaussmf',[1.5 5]
MF3='high':'gaussmf',[1.5 10]
[Input3]
Name='Reactor_area'
Range=[0 10]
NumMFs=3
MF1='low':'gaussmf',[1.5 0]
MF2='medium':'gaussmf',[1.5 5]
MF3='high':'gaussmf',[1.5 10]
[Input4]
Name='Spent_fuel_pool_area'
Range=[0 10]
NumMFs=3
MF1='low':'gaussmf',[1.5 0]
MF2='medium':'gaussmf',[1.5 5]
MF3='high':'gaussmf',[1.5 10]
[Output1]
Name='Safeguardability'
Range=[0 10]
NumMFs=5
MF1='Very_low':'trimf',[-2.5 0 2.5]
MF2='Low':'trimf',[0 2.5 5]
MF3='Medium':'trimf',[2.5 5 7.5]
MF4='High':'trimf',[5 7.5 10]
MF5='Very_high':'trimf',[7.5 10 12.5]
Adam Danz
2023-2-9
No, this is not valid MATLAB syntax MF[1:5]
Neither is this MF1='Very_low':'trimf',[-2.5 0 2.5]
Which is why you must be getting error messages.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)