Create and Run a Simple App Using App Designer
App Designer provides a tutorial that guides you through the process of creating a simple app containing a plot and a slider. The slider controls the amplitude of the plotted function. You can create this app by running the tutorial, or you can follow the tutorial steps listed here.
Run the Tutorial
To run the tutorial in App Designer, open the App Designer Start Page and expand the Examples: General section. Then, select Interactive Tutorial.
Tutorial Steps for Creating the App
Perform the following steps in App Designer.
Drag an Axes component from the Component Library onto the canvas.
Drag a Slider component from the Component Library onto the canvas. Place it below the axes, as in the preceding image.
Replace the slider label text. Double-click the label and replace the word
Above the canvas, click Code View to edit the code. (Notice that you can switch back to edit your layout by clicking Design View.)
In the code view, add a callback function that executes MATLAB® commands whenever the user moves the slider. Right-click
app.AmplitudeSliderin the Component Browser. Then select Callbacks > Add ValueChangedFcn callback in the context menu. App Designer creates a callback function and places the cursor in the body of that function.
peaksfunction in the axes. Add this command to the second line of the
AmplitudeSliderValueChangedcallback:Notice that the
plotcommand specifies the target axes (
app.UIAxes) as the first argument. The target axes is always required when you call the
plotcommand in App Designer.
Change the limits of the y-axis by setting the
YLimproperty of the
UIAxesobject. Add this command to the third line of the
AmplitudeSliderValueChangedcallback:Notice that the command uses dot notation to access the
app.UIAxes.YLim = [-1000 1000];
YLimproperty. Always use the pattern
Propertyto access property values.
Click Run to save and run the app. After saving your changes, your app is available for running again in App Designer, or by typing its name (without the
.mlappextension) at the MATLAB command prompt. When you run the app from the command prompt, the file must be in the current folder or on the MATLAB path.