Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- classdef MatlabBramkiLogiczne < matlab.apps.AppBase
- % Properties that correspond to app components
- properties (Access = public)
- UIFigure matlab.ui.Figure
- CalculateButton matlab.ui.control.Button
- LogicgateDropDownLabel matlab.ui.control.Label
- LogicgateDropDown matlab.ui.control.DropDown
- OutputEditFieldLabel matlab.ui.control.Label
- OutputEditField matlab.ui.control.NumericEditField
- InputaDropDownLabel matlab.ui.control.Label
- InputaDropDown matlab.ui.control.DropDown
- InputbDropDownLabel matlab.ui.control.Label
- InputbDropDown matlab.ui.control.DropDown
- end
- methods (Access = private)
- % Button pushed function: CalculateButton
- function CalculateButtonPushed(app, event)
- inputA = str2double(app.InputaDropDown.Value);
- inputB = str2double(app.InputbDropDown.Value);
- logicGate = app.LogicgateDropDown.Value;
- if(strcmp(logicGate,"NOT"))
- app.OutputEditField.Value = double(not(inputA));
- end
- if(strcmp(logicGate,"AND"))
- app.OutputEditField.Value = double(and(inputA,inputB));
- end
- if(strcmp(logicGate,"NAND"))
- app.OutputEditField.Value = double(not(and(inputA,inputB)));
- end
- if(strcmp(logicGate,"OR"))
- app.OutputEditField.Value = double(or(inputA,inputB));
- end
- if(strcmp(logicGate,"NOR"))
- app.OutputEditField.Value = double(not(or(inputA,inputB)));
- end
- if(strcmp(logicGate,"XOR"))
- app.OutputEditField.Value = double(xor(inputA,inputB));
- end
- if(strcmp(logicGate,"XNOR"))
- app.OutputEditField.Value = double(not(xor(inputA,inputB)));
- end
- end
- % Value changed function: LogicgateDropDown
- function LogicgateDropDownValueChanged(app, event)
- value = app.LogicgateDropDown.Value;
- if strcmp(value,"NOT")
- app.InputbDropDown.Enable = 'off'
- else
- app.InputbDropDown.Enable = 'on'
- end
- end
- end
- % App initialization and construction
- methods (Access = private)
- % Create UIFigure and components
- function createComponents(app)
- % Create UIFigure
- app.UIFigure = uifigure;
- app.UIFigure.Position = [100 100 543 250];
- app.UIFigure.Name = 'UI Figure';
- % Create CalculateButton
- app.CalculateButton = uibutton(app.UIFigure, 'push');
- app.CalculateButton.ButtonPushedFcn = createCallbackFcn(app, @CalculateButtonPushed, true);
- app.CalculateButton.Position = [213 27 100 22];
- app.CalculateButton.Text = 'Calculate';
- % Create LogicgateDropDownLabel
- app.LogicgateDropDownLabel = uilabel(app.UIFigure);
- app.LogicgateDropDownLabel.HorizontalAlignment = 'right';
- app.LogicgateDropDownLabel.Position = [29 200 62 15];
- app.LogicgateDropDownLabel.Text = 'Logic gate';
- % Create LogicgateDropDown
- app.LogicgateDropDown = uidropdown(app.UIFigure);
- app.LogicgateDropDown.Items = {'NOT', 'AND', 'NAND', 'OR', 'NOR', 'XOR', 'XNOR'};
- app.LogicgateDropDown.ValueChangedFcn = createCallbackFcn(app, @LogicgateDropDownValueChanged, true);
- app.LogicgateDropDown.Position = [106 196 100 22];
- app.LogicgateDropDown.Value = 'AND';
- % Create OutputEditFieldLabel
- app.OutputEditFieldLabel = uilabel(app.UIFigure);
- app.OutputEditFieldLabel.HorizontalAlignment = 'right';
- app.OutputEditFieldLabel.Position = [363 31 41 15];
- app.OutputEditFieldLabel.Text = 'Output';
- % Create OutputEditField
- app.OutputEditField = uieditfield(app.UIFigure, 'numeric');
- app.OutputEditField.Limits = [0 1];
- app.OutputEditField.Editable = 'off';
- app.OutputEditField.Position = [419 27 100 22];
- % Create InputaDropDownLabel
- app.InputaDropDownLabel = uilabel(app.UIFigure);
- app.InputaDropDownLabel.HorizontalAlignment = 'right';
- app.InputaDropDownLabel.Position = [52 147 47 15];
- app.InputaDropDownLabel.Text = 'Input(a)';
- % Create InputaDropDown
- app.InputaDropDown = uidropdown(app.UIFigure);
- app.InputaDropDown.Items = {'1', '0'};
- app.InputaDropDown.Position = [114 143 100 22];
- app.InputaDropDown.Value = '1';
- % Create InputbDropDownLabel
- app.InputbDropDownLabel = uilabel(app.UIFigure);
- app.InputbDropDownLabel.HorizontalAlignment = 'right';
- app.InputbDropDownLabel.Position = [52 107 47 15];
- app.InputbDropDownLabel.Text = 'Input(b)';
- % Create InputbDropDown
- app.InputbDropDown = uidropdown(app.UIFigure);
- app.InputbDropDown.Items = {'1', '0'};
- app.InputbDropDown.Position = [114 103 100 22];
- app.InputbDropDown.Value = '1';
- end
- end
- methods (Access = public)
- % Construct app
- function app = MatlabBramkiLogiczne
- % Create and configure 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement