Table of contents
In the past, our computers were still like this
With the continuous advancement of technology, our computers have also undergone earth-shaking changes in the 1990s:
In the future, our computers may look like this:
Today we are going to learn how to use the graphical interface of Matlab! ! !
1.MatlabGUI
guide%图形化界面
Then we come to our graphical interface
Push Button | When a button is pressed an action is produced |
Slider _ | The slider accepts numeric input within a specified range by allowing the user to move the slider |
Radio Button | Radio buttons are similar to checkboxes, but radio buttons are usually mutually exclusive within a group of related radio buttons. |
Check Box | Checkboxes can produce actions when selected and indicate whether their status is checked or unchecked |
Edit Text | Edit text component is a field that allows users to enter or modify text strings. Use edit text when text is required as input. |
Static Text | Static text component displays this text line |
Pop-Up Menu | Popup menu opens, showing a list of options when the user clicks the arrow |
List Box | A list box displays a list of items and allows the user to select one or more items |
Toggle Button | Toggle buttons generate an action and indicate whether they are on or off |
Table | Create a table component using table buttons |
Axes | Can display graphics |
1.1 Axes + normal buttons
1.1.1 Aligning components
We see that the position of our small buttons on the right is not very beautiful. What should we do to change their position?
result:
1.1.2 Button properties
An Object always has a unique id, which we can find in the properties
We can achieve the desired effect by modifying the attribute values:
1.1.3 Script description
Each button corresponds to a script. If you want to add events to the corresponding button, you must write code in the corresponding script function.
Let's add code to the main page now and see what happens?
handles.peaks=peaks(35);
handles.membrane=membrane;
[x,y] = meshgrid(-8:.5:8);
r = sqrt(x.^2+y.^2) + eps;
sinc = sin(r)./r;
handles.sinc = sinc;
handles.current_data = handles.peaks;
surf(handles.current_data)
After we save the script, our GUI interface will change, but our expectation is that this image is only allowed to appear when we click the button1 button, which does not meet our expectations.
Let's click the button1 button again to see if it is the same as we expected.
1.1.4 Select presentation
We want to show in the newly added image, we first find
Modify the code in the script of our button1 button and specify the rendered Object
surf(handles.axes2,handles.current_data)
%或者是
axes(handles.axes2);
surf(handles.current_data);
1.2 Slider + static text
When pulling, the text box above does not change because we have not yet associated the two Objects.
a = get(handles.slider2, 'Value');
set(handles.text2, 'String', 'TEST');
1.3 Compile GUI program
The corresponding programs can be run on our computer, but on another computer, these programs may not be able to run, so this is how we compile them
deploytool
Just wait