

The controls are the buttons that the user clicks to obtain a determined output. Users can enter scalar or vector values into Input dialog boxes.This is done by providing intuitive controls. To block program execution until the user responds, use the uiwait function. MATLAB program execution continues even when a modal input dialog box is active.

The names of each component will not be visible, unless we make it so.To make the names visible, we follow the procedure below: This is where we implement our user interface before writing the callback for the components.The design will be done on the canvas using the aligned components on the left side of the window. On selection of the template, the workspace opens up.
Changing the position can be done by double-clicking and dragging it.Let’s look at each of the components before using them. The size of the components can be changed by dragging the edges. To activate these changes, click on apply then OK.How to enable the name components to be visibleHere the components and their names are visibleTo add a component to the workspace, you select it and drop it there. Select the show names in the component palette.
When the button contains a solid circle within the hollow circle, then it is on. Its state can be changed by clicking on it. Radio Button – It has on and off states. The pad position can be changed by dragging the pad to the required position or click the forward or backward arrow. The callback function is called and executed when the user changes the pad position. Slider - It is similar to a scroll bar with numerical value.
The on state is represented by a tick inside the box. Check Box – It has the on and off state. They are grouped and only one can be on at a time.
You click on it to view the selections and the callback function is executed depending on the selection. Pop-up Menu – It is for listing selections. Static Text – Is to add labels that remain unchanged on the GUI and has no callbacks. The input can then be modified to numbers using str2num or the str2double function. Edit Text – Is for getting strings as an input from the user.
Table – It is used for the addition of a spreadsheet to the GUI. It’s the appearance that makes the difference. Toggle Button – It functions similarly to the radio button but different appearance in the GUI. In the list box, all the selections are visible throughout unlike the pop-up menu where only the current selection is visible.
Panel – It is for used to group several components and names according to the functionality. They have no callback function. Axes – Are for the addition of images, charts, and plots to the GUI.
When you double-click the component that you want to modify, a new window opens up as shown:We can also achieve this by clicking the property inspector situated at the top of the window.We can change the background color, foreground color, font size, font weight, string, and the tag of the components depending on the design structure.When modifying the string components, ensure that the name is meaningful, which helps identify the callback in the. We first add the required components - Panel, Static text, Axes, Push Button, Slider, and Edit Text.Add the components as explained earlier and arrange them as shown below:We then modify the components as needed. Similar to a panel, we first add the button group before adding the radio buttons.We want to create a simple GUI. When we group the radio buttons here. Button Group – It is just like the panel but used to group radio buttons.
This is done by initializing the properties. Fig file shows up.The object is first created and properties are set before the create function is called.The create function can also be used in the modification of the components rather than using the property inspector. M file is automatically generated before the. Upon running the GUI, the.
Matlab Gui User Input Code After A
Since edit text only accepts a string as input, we convert it using str2double function. Select the callback and it will automatically drive you there.Add the following code after a comment that begins %str2double.%str2double(get(hObject,'String')) returns contents of Amp as a doubleAmp = str2double(get(hObject, 'String')) % If the `amp` is not a number(nan) and the input should be a number(real) % the refresh button should be disabled.Set(hObject, 'String', 'Error: Not a number')We use the get function to obtain the user input. Right-click and select the view callback. The error checking ensures that the user inputs a number.We will first look at the callback function for the edit box and this is how we locate its callback function in the. We will require the callback function for refresh and edit text for error checking. It takes the current value from the slider as the frequency, gets the user input that computes amplitude.When the user clicks the refresh button, it executes the callback functions and draws a sine wave using the obtained data.
Write this code below the comment that begins with %handles structure:Note that the position of your code in the callback does not hinder the execution of the code since they are comments which are not executed but make the program more understandable.% handles structure with handles and user data (see GUIDATA)Freq = minFreq + fs * (maxFreq - minFreq) Amp = str2double(get(handles.Amp, 'String')) In the program above, we give data that helps in the interpretation of the value of the slider, that is, minFreq and maxFreq. Then it invokes the callback.Below is the callback for the refresh button. If it is real, we enable the refresh button by executing set(handles.ref, 'Enable', 'on').

This makes it an important tool for engineers implementing it in their projects. The purpose of the GUI is to create an interface to be used by everyone. This makes Matlab an efficient tool for creating GUI.
