Creating Graphical User Interfaces - The MathWorks - #49

/ 520


catalogue search
P. 01
P. 02
P. 03
P. 04
P. 05
P. 06
P. 07
P. 08
P. 09
P. 10
P. 11
P. 12
P. 13
P. 14
P. 15
P. 16
P. 17
P. 18
P. 19
P. 20
P. 21
P. 22
P. 23
P. 24
P. 25
P. 26
P. 27
P. 28
P. 29
P. 30
P. 31
P. 32
P. 33
P. 34
P. 35
P. 36
P. 37
P. 38
P. 39
P. 40
P. 41
P. 42
P. 43
P. 44
P. 45
P. 46
P. 47
P. 48
P. 49
P. 50


See other catalogues for The MathWorks

Text version of the page
Programming a Simple GUI
This code first retrieves two pop-up menu properties:
• String — a cell array that contains the menu contents
• Value — the index into the menu contents of the selected data set
It then uses a switch statement to make the selected data set the current data. The last statement saves the changes to the handles structure.
% Determine the selected data set.
str = get(hObject, 'String');
val = get(hObject,'Value');
% Set current data to the selected data set.
switch str{val};
case 'Peaks' % User selects peaks.
handles.current_data = handles.peaks; case 'Membrane' % User selects membrane.
handles.current_data = handles.membrane; case 'Sinc' % User selects sinc.
handles.current_data = handles.sinc;
end
% Save the handles structure. guidata(hObject,handles)
Programming the Push Buttons
Each of the push buttons creates a different type of plot using the data specified by the current selection in the pop-up menu. The push button callbacks get data from the handles structure and then plot it.
2-25

pageCatalog pdf di En 2012-06-22-01