How to create matlab.apps
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
UIAxes matlab.ui.control.UIAxes
ThetaSliderLabel matlab.ui.control.Label
ThetaSlider matlab.ui.control.Slider
FrequencyKnobLabel matlab.ui.control.Label
FrequencyKnob matlab.ui.control.Knob
StartButton matlab.ui.control.Button
GaugeLabel matlab.ui.control.Label
Gauge matlab.ui.control.SemicircularGauge
AmplitudeSliderLabel matlab.ui.control.Label
AmplitudeSlider matlab.ui.control.Slider
end
methods (Access = private)
% Callback function: AmplitudeSlider, AmplitudeSlider,
% FrequencyKnob, FrequencyKnob, StartButton, ThetaSlider,
% ThetaSlider
function StartButtonPushed(app, event)
Theta = app.ThetaSlider.Value;
freq = app.FrequencyKnob.Value;
Ampl = app.AmplitudeSlider.Value;
time = 0:0.2:10;
volt = Ampl*sin(freq*time+Theta);
plot(app.UIAxes,time,volt);
for i = 1:length(volt)
app.Gauge.Value = volt(i);
pause(1);
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 648 480];
app.UIFigure.Name = 'UI Figure';
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Title')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
app.UIAxes.Position = [207 203 302 202];
% Create ThetaSliderLabel
app.ThetaSliderLabel = uilabel(app.UIFigure);
app.ThetaSliderLabel.HorizontalAlignment = 'right';
app.ThetaSliderLabel.Position = [1 395 36 22];
app.ThetaSliderLabel.Text = 'Theta';
% Create ThetaSlider
app.ThetaSlider = uislider(app.UIFigure);
app.ThetaSlider.Limits = [-90 90];
app.ThetaSlider.ValueChangedFcn = createCallbackFcn(app, @StartButtonPushed, true);
app.ThetaSlider.ValueChangingFcn = createCallbackFcn(app, @StartButtonPushed, true);
app.ThetaSlider.Position = [58 404 150 3];
% Create AmplitudeSliderLabel
app.AmplitudeSliderLabel = uilabel(app.UIFigure);
app.AmplitudeSliderLabel.HorizontalAlignment = 'right';
app.AmplitudeSliderLabel.Position = [11 124 59 22];
app.AmplitudeSliderLabel.Text = 'Amplitude';
% Create AmplitudeSlider
app.AmplitudeSlider = uislider(app.UIFigure);
app.AmplitudeSlider.Limits = [0 20];
app.AmplitudeSlider.ValueChangedFcn = createCallbackFcn(app, @StartButtonPushed, true);
app.AmplitudeSlider.ValueChangingFcn = createCallbackFcn(app, @StartButtonPushed, true);
app.AmplitudeSlider.Position = [92 134 150 3];
app.AmplitudeSlider.Value = 5;
% Create FrequencyKnobLabel
app.FrequencyKnobLabel = uilabel(app.UIFigure);
app.FrequencyKnobLabel.HorizontalAlignment = 'center';
app.FrequencyKnobLabel.Position = [91 186 62 22];
app.FrequencyKnobLabel.Text = 'Frequency';
% Create FrequencyKnob
app.FrequencyKnob = uiknob(app.UIFigure, 'continuous');
app.FrequencyKnob.Limits = [0 10];
app.FrequencyKnob.ValueChangedFcn = createCallbackFcn(app, @StartButtonPushed, true);
app.FrequencyKnob.ValueChangingFcn = createCallbackFcn(app, @StartButtonPushed, true);
app.FrequencyKnob.Position = [91 242 60 60];
app.FrequencyKnob.Value = 2;
% Create StartButton
app.StartButton = uibutton(app.UIFigure, 'push');
app.StartButton.ButtonPushedFcn = createCallbackFcn(app, @StartButtonPushed, true);
app.StartButton.Position = [91 38 100 22];
app.StartButton.Text = 'Start';
% Create GaugeLabel
app.GaugeLabel = uilabel(app.UIFigure);
app.GaugeLabel.HorizontalAlignment = 'center';
app.GaugeLabel.Position = [368 59 42 22];
app.GaugeLabel.Text = 'Gauge';
% Create Gauge
app.Gauge = uigauge(app.UIFigure, 'semicircular');
app.Gauge.Limits = [-20 20];
app.Gauge.Position = [328 96 120 65];
end
end
methods (Access = public)
% Construct app
function app = app6
% 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

0 Comments