Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.91 KB | None | 0 0
  1. classdef MatlabBramkiLogiczne < matlab.apps.AppBase
  2.  
  3. % Properties that correspond to app components
  4. properties (Access = public)
  5. UIFigure matlab.ui.Figure
  6. CalculateButton matlab.ui.control.Button
  7. LogicgateDropDownLabel matlab.ui.control.Label
  8. LogicgateDropDown matlab.ui.control.DropDown
  9. OutputEditFieldLabel matlab.ui.control.Label
  10. OutputEditField matlab.ui.control.NumericEditField
  11. InputaDropDownLabel matlab.ui.control.Label
  12. InputaDropDown matlab.ui.control.DropDown
  13. InputbDropDownLabel matlab.ui.control.Label
  14. InputbDropDown matlab.ui.control.DropDown
  15. end
  16.  
  17. methods (Access = private)
  18.  
  19. % Button pushed function: CalculateButton
  20. function CalculateButtonPushed(app, event)
  21. inputA = str2double(app.InputaDropDown.Value);
  22. inputB = str2double(app.InputbDropDown.Value);
  23. logicGate = app.LogicgateDropDown.Value;
  24.  
  25. if(strcmp(logicGate,"NOT"))
  26. app.OutputEditField.Value = double(not(inputA));
  27. end
  28. if(strcmp(logicGate,"AND"))
  29. app.OutputEditField.Value = double(and(inputA,inputB));
  30. end
  31. if(strcmp(logicGate,"NAND"))
  32. app.OutputEditField.Value = double(not(and(inputA,inputB)));
  33. end
  34. if(strcmp(logicGate,"OR"))
  35. app.OutputEditField.Value = double(or(inputA,inputB));
  36. end
  37. if(strcmp(logicGate,"NOR"))
  38. app.OutputEditField.Value = double(not(or(inputA,inputB)));
  39. end
  40. if(strcmp(logicGate,"XOR"))
  41. app.OutputEditField.Value = double(xor(inputA,inputB));
  42. end
  43. if(strcmp(logicGate,"XNOR"))
  44. app.OutputEditField.Value = double(not(xor(inputA,inputB)));
  45. end
  46. end
  47.  
  48. % Value changed function: LogicgateDropDown
  49. function LogicgateDropDownValueChanged(app, event)
  50. value = app.LogicgateDropDown.Value;
  51. if strcmp(value,"NOT")
  52. app.InputbDropDown.Enable = 'off'
  53. else
  54. app.InputbDropDown.Enable = 'on'
  55. end
  56. end
  57. end
  58.  
  59. % App initialization and construction
  60. methods (Access = private)
  61.  
  62. % Create UIFigure and components
  63. function createComponents(app)
  64.  
  65. % Create UIFigure
  66. app.UIFigure = uifigure;
  67. app.UIFigure.Position = [100 100 543 250];
  68. app.UIFigure.Name = 'UI Figure';
  69.  
  70. % Create CalculateButton
  71. app.CalculateButton = uibutton(app.UIFigure, 'push');
  72. app.CalculateButton.ButtonPushedFcn = createCallbackFcn(app, @CalculateButtonPushed, true);
  73. app.CalculateButton.Position = [213 27 100 22];
  74. app.CalculateButton.Text = 'Calculate';
  75.  
  76. % Create LogicgateDropDownLabel
  77. app.LogicgateDropDownLabel = uilabel(app.UIFigure);
  78. app.LogicgateDropDownLabel.HorizontalAlignment = 'right';
  79. app.LogicgateDropDownLabel.Position = [29 200 62 15];
  80. app.LogicgateDropDownLabel.Text = 'Logic gate';
  81.  
  82. % Create LogicgateDropDown
  83. app.LogicgateDropDown = uidropdown(app.UIFigure);
  84. app.LogicgateDropDown.Items = {'NOT', 'AND', 'NAND', 'OR', 'NOR', 'XOR', 'XNOR'};
  85. app.LogicgateDropDown.ValueChangedFcn = createCallbackFcn(app, @LogicgateDropDownValueChanged, true);
  86. app.LogicgateDropDown.Position = [106 196 100 22];
  87. app.LogicgateDropDown.Value = 'AND';
  88.  
  89. % Create OutputEditFieldLabel
  90. app.OutputEditFieldLabel = uilabel(app.UIFigure);
  91. app.OutputEditFieldLabel.HorizontalAlignment = 'right';
  92. app.OutputEditFieldLabel.Position = [363 31 41 15];
  93. app.OutputEditFieldLabel.Text = 'Output';
  94.  
  95. % Create OutputEditField
  96. app.OutputEditField = uieditfield(app.UIFigure, 'numeric');
  97. app.OutputEditField.Limits = [0 1];
  98. app.OutputEditField.Editable = 'off';
  99. app.OutputEditField.Position = [419 27 100 22];
  100.  
  101. % Create InputaDropDownLabel
  102. app.InputaDropDownLabel = uilabel(app.UIFigure);
  103. app.InputaDropDownLabel.HorizontalAlignment = 'right';
  104. app.InputaDropDownLabel.Position = [52 147 47 15];
  105. app.InputaDropDownLabel.Text = 'Input(a)';
  106.  
  107. % Create InputaDropDown
  108. app.InputaDropDown = uidropdown(app.UIFigure);
  109. app.InputaDropDown.Items = {'1', '0'};
  110. app.InputaDropDown.Position = [114 143 100 22];
  111. app.InputaDropDown.Value = '1';
  112.  
  113. % Create InputbDropDownLabel
  114. app.InputbDropDownLabel = uilabel(app.UIFigure);
  115. app.InputbDropDownLabel.HorizontalAlignment = 'right';
  116. app.InputbDropDownLabel.Position = [52 107 47 15];
  117. app.InputbDropDownLabel.Text = 'Input(b)';
  118.  
  119. % Create InputbDropDown
  120. app.InputbDropDown = uidropdown(app.UIFigure);
  121. app.InputbDropDown.Items = {'1', '0'};
  122. app.InputbDropDown.Position = [114 103 100 22];
  123. app.InputbDropDown.Value = '1';
  124. end
  125. end
  126.  
  127. methods (Access = public)
  128.  
  129. % Construct app
  130. function app = MatlabBramkiLogiczne
  131.  
  132. % Create and configure components
  133. createComponents(app)
  134.  
  135. % Register the app with App Designer
  136. registerApp(app, app.UIFigure)
  137.  
  138. if nargout == 0
  139. clear app
  140. end
  141. end
  142.  
  143. % Code that executes before app deletion
  144. function delete(app)
  145.  
  146. % Delete UIFigure when app is deleted
  147. delete(app.UIFigure)
  148. end
  149. end
  150. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement