MATLAB GUI Quick Start Production

Create a blank GUI
input command line guide MATLAB
new GUI, select Blank GUI (Default), and click OK generated after a production blank GUI screen, as shown in FIG.


FIG 1
specific process of making the GUI
simple adder
will be dragged into editable text interface
Double-editable text, can modify the text String field, Tag column corresponds to each tag is a text input in the back output link role is very big.
Static text dragged into the interface, double-click it, can also modify the text String field; Similarly, drag a button interface, to modify the String operation, it acts as a switch to run the program.
Click on the menu bar align objects, select the corresponding component in the interface, to adjust the layout to give the following results

2
The first two editable text input, the latter is output, select the Run, right-click and select View pullback in the Callback, write the statement in pushbuttonX_Callback function (where X represents your specific Tag is set to run in how much)
Global A1;
Global A2;
A3 Global;
A1 = str2double (GET (handles.edit1, 'String'));
A2 = str2double (GET (handles.edit2, 'String'));
A3 = A1 + A2 ;
SET (handles.edit3, 'String', A3);
. 1
2
. 3
. 4
. 5
. 6
. 7
click GUI interface menu bar operation pattern, the input data in the front two editable text, click operation to give the following results

image 3

PS:
1, in fact, make GUI is not complicated, m theory, any program you write can be packaged into a GUI, you only need to solve the problem of input parameters and output results.
2, in the preparation of the program, discover define a global variable in a function s A, which wants to use another function at B, must be re s global variable in function B (hereinafter referred to will continue).
Importing data EXCEl
MATLAB is a tool for processing data in the actual process, you may need to import data into the GUI, detailed below:

FIG need to import data:


Figure 4
then drag a button interface, modify the String to import data, select it, right-click callback → View → Callback, write the following statement in pushbuttonX_Callback function.
SJ Global;
[fname_od, pname_od] = uigetfile ( 'XLSX.', 'Please select the data you want to import');
IF fname_od == 0
return
End
STR = fullfile (pname_od, fname_od);
[NUM, TXT, SJ] = xlsread (str);
% action by the following statement is to delete data of the first row
SJ (. 1, :) = [];
SJ = cell2mat (SJ);
% introducing incoming cellular array is a need to convert a matrix
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
in the above code, the corresponding modifications may be made according to their actual needs, such as the file format xls, then uigetfile can be changed xls xlsx

Displaying the GUI data in
drag in a GUI interface table, then it should be Tag uitable1, select it, right-click → correction → CreateFcn view
input uitableX_CreateFcn function in the following procedure:
the DATA = {0,0,0, 0,0,0}
initial value table of the%
set (hObject, 'ColumnName', { ' language', 'mathematics,' 'English', 'physical', 'chemical', 'biological'}, 'data', DATA , ...
'ColumnEditable', to true);
% set the table column name
. 1
2
. 3
. 4
. 5
in the GUI interface, click on the menu bar operation pattern, after the adjustment of the layout, as shown in the results obtained:


5
Select the Run button, right-click callback → View → Callback, continue to write the statement in pushbuttonX_Callback function
, Ltd. Free Join SJ;
% here is once again define global variables in the above-mentioned
set (handles.uitable1, 'data', SJ);
. 1
2
. 3
in the GUI interface, click operation pattern, the input data in an editable text, data import button click, pop-up interface in FIG.

6
selects the EXCEL data file, and then click the Run button, the following results can be obtained


7
after the above step, although only describes how to import data into GUI, and the GUI derive the original data, but you can import relevant data processed by the method described above, the output result according to actual needs.
Brief pop-up menu in
the drop-down menu is common GUI components, the following related description of its use

The pop-up menu dragged into the GUI interface, double-click it, click on the small square in the String field, enter what you need in it, as

FIG 8
is selected → Check pop-up menu callback → Callback, enter the following code popupmenuX_Callback function
Global A4;
Val = GET (handles.popupmenu1, 'value');
Switch Val
Case. 1
A4 = 0;
Case 2
A4 =. 5;
Case . 3
A4 =. 9;
case. 4
A4 = 15;
End
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
12 is
selected to run → Check callback → callback, write the statement at pushbuttonX_Callback function
Global A1;
Global A2;
Global A3;
Global A4 ;

a1 = str2double(get(handles.edit1,'String'));
a2 = str2double(get(handles.edit2,'String'));
a3 = a1 + a2 + a4;
set(handles.edit3,'String',a3);

SJ Global;
SET (handles.uitable1, 'Data', SJ);
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
12 is
click run graphics GUI menu bar, select the data you want in the drop down menu

Enter the data in the text, and import the data you want to process in accordance with the above procedure, click the Run button, the following results

 

9
Conclusion
The foregoing is're doing the project, access to relevant information that summed up some experience. Due to limited capacity, above inevitably there will be omissions and errors, welcome Gangster criticism.
--------------------- 

Guess you like

Origin www.cnblogs.com/ly570/p/10989728.html