MATLAB Answers

Info

This question is closed. Reopen it to edit or answer.

Please Help I have this code however, I don't know how to input it in MATLAB. I am practicing how to make apps

4 views (last 30 days)
Raphael Marcelo
Raphael Marcelo on 7 May 2021
Closed: Rena Berman on 29 Jun 2021 at 15:25
classdef ElectricalApp < matlab.apps.AppBase % Properties that correspond to app components properties (Access = public) UIFigure matlab.ui.Figure R1EditFieldLabel matlab.ui.control.Label R1EditField matlab.ui.control.NumericEditField R2EditFieldLabel matlab.ui.control.Label R2EditField matlab.ui.control.NumericEditField R3EditFieldLabel matlab.ui.control.Label R3EditField matlab.ui.control.NumericEditField V1EditFieldLabel matlab.ui.control.Label V1EditField matlab.ui.control.NumericEditField V2EditFieldLabel matlab.ui.control.Label V2EditField matlab.ui.control.NumericEditField ResistorsOhmLabel matlab.ui.control.Label VoltageSourcesVoltLabel matlab.ui.control.Label I1EditFieldLabel matlab.ui.control.Label I1EditField matlab.ui.control.NumericEditField OutputCurrentsALabel matlab.ui.control.Label I2EditFieldLabel matlab.ui.control.Label I2EditField matlab.ui.control.NumericEditField I3EditFieldLabel matlab.ui.control.Label I3EditField matlab.ui.control.NumericEditField CalculateButton matlab.ui.control.Button end % Callbacks that handle component events methods (Access = private) % Button pushed function: CalculateButton function CalculateButtonPushed(app, event) R1 = app.R1EditField.Value; R2 = app.R2EditField.Value; R3 = app.R3EditField.Value; V1 = app.V1EditField.Value; V2 = app.V2EditField.Value; syms I1 I2 I3; eqn1 = I1*R1 + I2*R2 == V2 - V1; eqn2 = I2*R2 + I3*R3 == V2; eqn3 = I1 + I3 - I2 == 0; [A,B] = equationsToMatrix([eqn1, eqn2, eqn3], [I1, I2, I3]); X = linsolve(A,B); app.I1EditField.Value = double(X(1)); app.I2EditField.Value = double(X(2)); app.I3EditField.Value = double(X(3)); 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 640 480]; app.UIFigure.Name = 'MATLAB App'; % Create R1EditFieldLabel app.R1EditFieldLabel = uilabel(app.UIFigure); app.R1EditFieldLabel.HorizontalAlignment = 'right'; app.R1EditFieldLabel.Position = [20 430 25 22]; app.R1EditFieldLabel.Text = 'R1'; % Create R1EditField app.R1EditField = uieditfield(app.UIFigure, 'numeric'); app.R1EditField.Position = [60 430 100 22]; % Create R2EditFieldLabel app.R2EditFieldLabel = uilabel(app.UIFigure); app.R2EditFieldLabel.HorizontalAlignment = 'right'; app.R2EditFieldLabel.Position = [20 384 25 22]; app.R2EditFieldLabel.Text = 'R2'; % Create R2EditField app.R2EditField = uieditfield(app.UIFigure, 'numeric'); app.R2EditField.Position = [60 384 100 22]; % Create R3EditFieldLabel app.R3EditFieldLabel = uilabel(app.UIFigure); app.R3EditFieldLabel.HorizontalAlignment = 'right'; app.R3EditFieldLabel.Position = [20 334 25 22]; app.R3EditFieldLabel.Text = 'R3'; % Create R3EditField app.R3EditField = uieditfield(app.UIFigure, 'numeric'); app.R3EditField.Position = [60 334 100 22]; % Create V1EditFieldLabel app.V1EditFieldLabel = uilabel(app.UIFigure); app.V1EditFieldLabel.HorizontalAlignment = 'right'; app.V1EditFieldLabel.Position = [363 430 25 22]; app.V1EditFieldLabel.Text = 'V1'; % Create V1EditField app.V1EditField = uieditfield(app.UIFigure, 'numeric'); app.V1EditField.Position = [403 430 100 22]; % Create V2EditFieldLabel app.V2EditFieldLabel = uilabel(app.UIFigure); app.V2EditFieldLabel.HorizontalAlignment = 'right'; app.V2EditFieldLabel.Position = [363 384 25 22]; app.V2EditFieldLabel.Text = 'V2'; % Create V2EditField app.V2EditField = uieditfield(app.UIFigure, 'numeric'); app.V2EditField.Position = [403 384 100 22]; % Create ResistorsOhmLabel app.ResistorsOhmLabel = uilabel(app.UIFigure); app.ResistorsOhmLabel.Position = [75 457 93 24]; app.ResistorsOhmLabel.Text = 'Resistors (Ohm)'; % Create VoltageSourcesVoltLabel app.VoltageSourcesVoltLabel = uilabel(app.UIFigure); app.VoltageSourcesVoltLabel.Position = [406 458 124 22]; app.VoltageSourcesVoltLabel.Text = 'Voltage Sources (Volt)'; % Create I1EditFieldLabel app.I1EditFieldLabel = uilabel(app.UIFigure); app.I1EditFieldLabel.HorizontalAlignment = 'right'; app.I1EditFieldLabel.Position = [60 157 25 22]; app.I1EditFieldLabel.Text = 'I1'; % Create I1EditField app.I1EditField = uieditfield(app.UIFigure, 'numeric'); app.I1EditField.Position = [100 157 100 22]; % Create OutputCurrentsALabel app.OutputCurrentsALabel = uilabel(app.UIFigure); app.OutputCurrentsALabel.Position = [273 201 110 22]; app.OutputCurrentsALabel.Text = 'Output Currents (A)'; % Create I2EditFieldLabel app.I2EditFieldLabel = uilabel(app.UIFigure); app.I2EditFieldLabel.HorizontalAlignment = 'right'; app.I2EditFieldLabel.Position = [224 157 25 22]; app.I2EditFieldLabel.Text = 'I2'; % Create I2EditField app.I2EditField = uieditfield(app.UIFigure, 'numeric'); app.I2EditField.Position = [264 157 100 22]; % Create I3EditFieldLabel app.I3EditFieldLabel = uilabel(app.UIFigure); app.I3EditFieldLabel.HorizontalAlignment = 'right'; app.I3EditFieldLabel.Position = [403 157 25 22]; app.I3EditFieldLabel.Text = 'I3'; % Create I3EditField app.I3EditField = uieditfield(app.UIFigure, 'numeric'); app.I3EditField.Position = [443 157 100 22]; % Create CalculateButton app.CalculateButton = uibutton(app.UIFigure, 'push'); app.CalculateButton.ButtonPushedFcn = createCallbackFcn(app, @CalculateButtonPushed, true); app.CalculateButton.Position = [126 269 352 22]; app.CalculateButton.Text = 'Calculate'; % 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 = ElectricalApp % 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

Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by