Geoscience Reference
In-Depth Information
of the edit text areas we choose 0 for the mean and 1 for the standard
deviation text area. We then place an axis with dimensions of 250-by-200
pixels to the right of the GUI. Next, we save and activate the GUI by selecting
Run from the To o l s menu. GUIDE displays a dialog box with the question
Activating will save changes ...? , where we click Ye s . In the following Save As
dialog box, we dei ne a FIG -i le name such as gaussiantool.i g .
GUIDE then saves this i gure i le together with the corresponding
MATLAB code in a second i le named gaussiantool.m . Furthermore, the
MATLAB code is opened in the Editor and the default GUI is opened in a
Figure Window with no menu or toolbar (Fig. 2.5). As we can see, GUIDE
has automatically programmed the code of our GUI layout, including an
initialization code at the beginning of the i le that we should not edit. h is
code is included in the main routine named gaussiantool . h e i le also
contains other functions called by gaussiantool , for instance the function
gaussiantool_Opening_Fcn (executed before gaussiantool is made visible),
gaussiantool_OutputFnc (sending output to the command line, not used
here), edit1_CreateFcn and edit2_CreateFcn (initializing the edit text areas
when they are created), and edit1_Callback and edit2_Callback (accepting
text input and returning this input either as text or as a double-precision
number).
We now add code to our GUI gaussiantool . First, we add initial values
for the global variables mmean and mstd in the opening function gaussiantool_
Opening_Fcn by adding the following lines at er the last comment line marked
by % in the i rst column:
global mmean mstd
mmean = 0;
mstd = 1;
h e two variables must be global because they are used in the callbacks that
we edit next (as in Section 2.8). h e i rst of these callbacks edit1_Callback
gets three more lines of code at er the last comment line:
global mmean
mmean = str2double(get(hObject,'String'));
calculating_gaussian(hObject, eventdata, handles)
h e i rst line dei nes the global variable mmean , which is then obtained by
converting the text input into double precision with str2double in the second
line. h e function edit1_Callback then calls the function calculating_gaussian ,
which is a new function at the end of the i le. h is function computes and
displays the Gaussian function with a mean value of mmean and a standard
deviation of mstd .
Movie
2.7
Search WWH ::




Custom Search