classdef QuartercarGUI < matlab.apps.AppBase
properties (Access = public)
UIFigure matlab.ui.Figure
m1kgEditFieldLabel matlab.ui.control.Label
m1kgEditField matlab.ui.control.NumericEditField
k1NmEditFieldLabel matlab.ui.control.Label
k1NmEditField matlab.ui.control.NumericEditField
b1NsmEditFieldLabel matlab.ui.control.Label
b1NsmEditField matlab.ui.control.NumericEditField
m2kgEditFieldLabel matlab.ui.control.Label
m2kgEditField matlab.ui.control.NumericEditField
k2NmEditFieldLabel matlab.ui.control.Label
k2NmEditField matlab.ui.control.NumericEditField
b2NsmEditFieldLabel matlab.ui.control.Label
b2NsmEditField matlab.ui.control.NumericEditField
WheelandSuspensionLabel matlab.ui.control.Label
QuarterCarLabel matlab.ui.control.Label
CalculateButton matlab.ui.control.Button
rdEditFieldLabel matlab.ui.control.Label
rdEditField matlab.ui.control.EditField
RoadProfileLabel matlab.ui.control.Label
rdprimeEditFieldLabel matlab.ui.control.Label
rdprimeEditField matlab.ui.control.EditField
UIAxes matlab.ui.control.UIAxes
UIAxes2 matlab.ui.control.UIAxes
end
methods (Access = private)
function CalculateButtonPushed(app, event)
function quartercar
m1 = app.m1kgEditField.Value;
m2 = app.m2kgEditField.Value;
b1 = app.b1NsmEditField.Value;
b2 = app.b2NsmEditField.Value;
k1 = app.k1NmEditField.Value;
k2 = app.k2NmEditField.Value;
rd = app.rdEditField.Value;
rdprime = app.rdprimeEditField.Value;
xone0 = 0; vone0 = 0;
xtwo0 = 0; vtwo0 = 0;
IC = [xone0, vone0, xtwo0, vtwo0];
t0 = 0; tf = 5;
tspan = [t0,tf];
sdot = @(t,s) ...
[s(2);
(-1/m1)*((k1*(s(1)-s(3))) + (b1*(s(2)-s(4))));
s(4);
((k1*(s(1)-s(3)) + b1*(s(2)-s(4)) -k2*(s(3)-rd(t)) -b2*(s(4)-rdprime(t)))/m2)];
[time, state_values] = ode45(sdot,tspan,IC);
xone = state_values(:,1);
vone = state_values(:,2);
xtwo = state_values(:,3);
vtwo = state_values(:,4);
plot(app.UIAxes,xone)
plot(app.UIAxes2,vone)
end
end
end
methods (Access = private)
function createComponents(app)
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'MATLAB App';
app.m1kgEditFieldLabel = uilabel(app.UIFigure);
app.m1kgEditFieldLabel.HorizontalAlignment = 'right';
app.m1kgEditFieldLabel.Position = [35 390 46 22];
app.m1kgEditFieldLabel.Text = 'm1 (kg)';
app.m1kgEditField = uieditfield(app.UIFigure, 'numeric');
app.m1kgEditField.Position = [96 390 100 22];
app.m1kgEditField.Value = 25;
app.k1NmEditFieldLabel = uilabel(app.UIFigure);
app.k1NmEditFieldLabel.HorizontalAlignment = 'right';
app.k1NmEditFieldLabel.Position = [30 352 51 22];
app.k1NmEditFieldLabel.Text = 'k1 (N/m)';
app.k1NmEditField = uieditfield(app.UIFigure, 'numeric');
app.k1NmEditField.Position = [96 352 100 22];
app.k1NmEditField.Value = 10;
app.b1NsmEditFieldLabel = uilabel(app.UIFigure);
app.b1NsmEditFieldLabel.HorizontalAlignment = 'right';
app.b1NsmEditFieldLabel.Position = [23 319 58 22];
app.b1NsmEditFieldLabel.Text = 'b1 (Ns/m)';
app.b1NsmEditField = uieditfield(app.UIFigure, 'numeric');
app.b1NsmEditField.Position = [96 319 100 22];
app.b1NsmEditField.Value = 15;
app.m2kgEditFieldLabel = uilabel(app.UIFigure);
app.m2kgEditFieldLabel.HorizontalAlignment = 'right';
app.m2kgEditFieldLabel.Position = [35 255 46 22];
app.m2kgEditFieldLabel.Text = 'm2 (kg)';
app.m2kgEditField = uieditfield(app.UIFigure, 'numeric');
app.m2kgEditField.Position = [96 255 100 22];
app.m2kgEditField.Value = 30;
app.k2NmEditFieldLabel = uilabel(app.UIFigure);
app.k2NmEditFieldLabel.HorizontalAlignment = 'right';
app.k2NmEditFieldLabel.Position = [30 220 51 22];
app.k2NmEditFieldLabel.Text = 'k2 (N/m)';
app.k2NmEditField = uieditfield(app.UIFigure, 'numeric');
app.k2NmEditField.Position = [96 220 100 22];
app.k2NmEditField.Value = 55;
app.b2NsmEditFieldLabel = uilabel(app.UIFigure);
app.b2NsmEditFieldLabel.HorizontalAlignment = 'right';
app.b2NsmEditFieldLabel.Position = [23 187 58 22];
app.b2NsmEditFieldLabel.Text = 'b2 (Ns/m)';
app.b2NsmEditField = uieditfield(app.UIFigure, 'numeric');
app.b2NsmEditField.Position = [96 187 100 22];
app.b2NsmEditField.Value = 12;
app.WheelandSuspensionLabel = uilabel(app.UIFigure);
app.WheelandSuspensionLabel.Position = [80 284 129 22];
app.WheelandSuspensionLabel.Text = 'Wheel and Suspension';
app.QuarterCarLabel = uilabel(app.UIFigure);
app.QuarterCarLabel.Position = [77 420 69 22];
app.QuarterCarLabel.Text = 'Quarter Car';
app.CalculateButton = uibutton(app.UIFigure, 'push');
app.CalculateButton.ButtonPushedFcn = createCallbackFcn(app, @CalculateButtonPushed, true);
app.CalculateButton.Position = [95 50 100 22];
app.CalculateButton.Text = 'Calculate';
app.rdEditFieldLabel = uilabel(app.UIFigure);
app.rdEditFieldLabel.HorizontalAlignment = 'right';
app.rdEditFieldLabel.Position = [56 130 25 22];
app.rdEditFieldLabel.Text = 'rd';
app.rdEditField = uieditfield(app.UIFigure, 'text');
app.rdEditField.Position = [96 130 100 22];
app.rdEditField.Value = '0.15*sin(time)^2';
app.RoadProfileLabel = uilabel(app.UIFigure);
app.RoadProfileLabel.Position = [110 151 71 22];
app.RoadProfileLabel.Text = 'Road Profile';
app.rdprimeEditFieldLabel = uilabel(app.UIFigure);
app.rdprimeEditFieldLabel.HorizontalAlignment = 'right';
app.rdprimeEditFieldLabel.Position = [32 92 46 22];
app.rdprimeEditFieldLabel.Text = 'rdprime';
app.rdprimeEditField = uieditfield(app.UIFigure, 'text');
app.rdprimeEditField.Position = [93 92 100 22];
app.rdprimeEditField.Value = '0.15*sin(2*time)';
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Displacement vs time')
xlabel(app.UIAxes, {'time'; ''})
ylabel(app.UIAxes, 'displacemnt')
zlabel(app.UIAxes, 'Z')
app.UIAxes.PlotBoxAspectRatio = [2.2027972027972 1 1];
app.UIAxes.Position = [269 257 300 185];
app.UIAxes2 = uiaxes(app.UIFigure);
title(app.UIAxes2, 'Velocity vs time')
xlabel(app.UIAxes2, 'time')
ylabel(app.UIAxes2, 'velocity')
zlabel(app.UIAxes2, 'Z')
app.UIAxes2.PlotBoxAspectRatio = [1.92638036809816 1 1];
app.UIAxes2.XTick = [0 1 2 3 4 5 6];
app.UIAxes2.XTickLabel = {'0'; '1'; '0'; '3'; '4'; '5'; '6'};
app.UIAxes2.Position = [269 24 300 185];
app.UIFigure.Visible = 'on';
end
end
methods (Access = public)
function app = QuartercarGUI
createComponents(app)
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
function delete(app)
delete(app.UIFigure)
end
end
end
8 Comments
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/654183-plot-in-app-designer#comment_1148388
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/654183-plot-in-app-designer#comment_1148388
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/654183-plot-in-app-designer#comment_1149283
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/654183-plot-in-app-designer#comment_1149283
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/654183-plot-in-app-designer#comment_1149358
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/654183-plot-in-app-designer#comment_1149358
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/654183-plot-in-app-designer#comment_1149523
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/654183-plot-in-app-designer#comment_1149523
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/654183-plot-in-app-designer#comment_1149573
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/654183-plot-in-app-designer#comment_1149573
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/654183-plot-in-app-designer#comment_1149578
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/654183-plot-in-app-designer#comment_1149578
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/654183-plot-in-app-designer#comment_1149618
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/654183-plot-in-app-designer#comment_1149618
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/654183-plot-in-app-designer#comment_1149628
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/654183-plot-in-app-designer#comment_1149628
Sign in to comment.