Documente Academic
Documente Profesional
Documente Cultură
Empty GUI – the Start
M‐file Initialization
• function varargout = ada_gui(varargin)
• % ADA_GUI M‐file for ada_gui.fig
• % ADA_GUI, by itself, creates a new ADA_GUI or raises the existing
• % singleton*.
• %
• % H = ADA_GUI returns the handle to a new ADA_GUI or the handle to
• % the existing singleton*.
• %
• % ADA_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
• % function named CALLBACK in ADA_GUI.M with the given input arguments.
• %
• % ADA_GUI('Property','Value',...) creates a new ADA_GUI or raises the
• % existing singleton*. Starting from the left, property value pairs are
• % applied to the GUI before ada_gui_OpeningFunction gets called. An
• % unrecognized property name or invalid value makes property application
• % stop. All inputs are passed to ada_gui_OpeningFcn via varargin.
• %
• % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
• % instance to run (singleton)".
• %
• % See also: GUIDE, GUIDATA, GUIHANDLES
•
• % Edit the above text to modify the response to help ada_gui
M‐file Opening Function
• function ada_gui_OpeningFcn(hObject, eventdata, handles, varargin)
• % This function has no output args, see OutputFcn.
• % hObject handle to figure
• % eventdata reserved ‐ to be defined in a future version of MATLAB
• % handles structure with handles and user data (see GUIDATA)
• % varargin command line arguments to ada_gui (see VARARGIN)
• The opening function sets the stage: i.e. you can assign constants,
initialize array’s, set colors on the GUI etc.
• You transfer the values using the so‐called handle structure: handles
handles
• Handles allow you to transfer all assignments and
results among the different functions of your GUI.
• You make them available: handles=guidata(hObject);
• This function reads all handles assigned to hObject.
After this, you can access the handle structure, e.g.
• myval=handles.value
• You have to update your handle structure at the end of
a function that has modified the handles. If you do not,
the changes are lost.
• guidata(hObject,handles)
M‐file Output Function
• function ada_gui_OpeningFcn(hObject, eventdata, handles, varargin)
• % This function has no output args, see OutputFcn.
• % hObject handle to figure
• % eventdata reserved ‐ to be defined in a future version of MATLAB
• % handles structure with handles and user data (see GUIDATA)
• % varargin command line arguments to ada_gui (see VARARGIN)
•
• % Choose default command line output for ada_gui
• The output function makes it possible to send parameters , images
back to the function that called the GUI
M‐file Utility Functions
M‐file Utility Functions
• Adding the ’axes1’ has identified an area
where images can be displayed
• Adding the ’Pushbutton1’ creates a container
function into which you can add functionality:
• % ‐‐‐ Executes on button press in pushbutton1.
• function pushbutton1_Callback(hObject, eventdata, handles)
• % hObject handle to pushbutton1 (see GCBO)
• % eventdata reserved ‐ to be defined in a future version of MATLAB
• % handles structure with handles and user data (see GUIDATA)
Creating your own function
• % ‐‐‐ Executes on button press in pushbutton1.
• function pushbutton1_Callback(hObject, eventdata, handles)
• % hObject handle to pushbutton1 (see GCBO)
• % eventdata reserved ‐ to be defined in a future version of MATLAB
• % handles structure with handles and user data (see GUIDATA)
• %here comes your functionality
• handles=guidata(hObject); %makes all assignments done in the opening function accesible
• [fname pathname]=uigetfile(‘*.jpg’); %the usual stuff
• fullpath=[pathname fname]; %the usual stuff
• myim=imread(fullpath); %the usual stuff
• axes(handles.axes1); % will make axes1 the current active axes
• imshow(myim) %will display the image in axes1
• Case two
• Add a slider that defines the cutoff.
Edit
• Th edit box can be placed anywhere and is
displaying an editable text, i.e. If you want to
display something in the edit1 box:
• set(handles.edit1,’String’,num2str(227))
• If you want the program to read something from
the edit1 box:
• mystr=get(handles.edit1,’String’)
• mystr is a string – thus if you want a number from
this string:
• mynum=str2num(mystr)
Slider
Slider
• A slider has several adjustable parameters:
• min
• max
• value
• sliderstep
• Each of the above has a default value – you can
see which by double clicking the GUI figure slider
Double Clicking a Slider
User interface options
• listdlg : will open a ’list dialogue’ window, where you
can select one or multiple options.
• str =
{'1';'2';'3';'4';'5';'6';'7';'8';'9';'10';'11';'12';'13';'14';'15';'
16';'17';'18';'19';'20';'25';'30';'35';'40';'45';'50';'60';'70'
;'80';'90';'100'};
• [s,v] = listdlg('PromptString','Select a number:',...
• 'SelectionMode','single',...
• 'ListString',str)
• handles.number=str2num(str{s});
Input Dialogue
• prompt={’Option'};
• name=’My Option';
• numlines=1;
• defaultanswer={'0.05'};
• answer=inputdlg(prompt,name,numlines,def
aultanswer);
Input dialogue – multiple options
• prompt={’option1',...
• ’option2'
• };
• name=‘My Option';
• numlines=1;
• defaultanswer={'0','0.01'};
• answer=inputdlg(prompt,name,numlines,def
aultanswer);
Call Me
• If your GUI is called ada
• You activate it very simple
• ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
• function mytest
• ada
• ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
• In this simple example, we do not pass
parameters to the ada gui.
Todays Problem
• Make a GUI that allow the user to read an
image of his choice
• The image should appear in axes1
• At a button choice the user will display the
Fourier Transform in a second axes, axes2
• The user should now be able to select
between the abs, real, imag and phase display
using a listdialogue box