Presentation is loading. Please wait.

Presentation is loading. Please wait.

PATTERN RECOGNITION LAB 8 TA : Nouf Al-Harbi::

Similar presentations


Presentation on theme: "PATTERN RECOGNITION LAB 8 TA : Nouf Al-Harbi::"— Presentation transcript:

1 PATTERN RECOGNITION LAB 8 TA : Nouf Al-Harbi:: nouf200@hotmail.com

2 Lab objective:  Dealing with GUI  Make Bayesian Classifier using GUI 2

3 3

4 Steps for making Bayesian classifier using GUI 4

5 Why use a GUI in MATLAB? 5  it makes things simple for the end-users of the program  If GUIs were not used, people would have to work from the command line interface  It can be extremely difficult and frustrating.

6 Steps for making Bayesian classifier using GUI 6  open up MATLAB  File  New  GUI

7 Final form we should have 7  8 Edit Text components  9 Static Text component  2 Pushbutton component  2 figures

8 Steps for making Bayesian classifier using GUI 8 Add in all these components to the GUI by clicking on the icon and placing it onto the grid

9 Steps for making Bayesian classifier using GUI 9  Its time to edit the properties of these components  Double click one of the components  You can also, Right-click the component and select property inspector

10 Steps for making Bayesian classifier using GUI 10  The Tag parameter is basically the variable name of this component  The String parameter is the text of this component

11 Steps for making Bayesian classifier using GUI 11  Now, save your GUI under any file name  When you save this file MATLAB automatically generates two files  myClassifier.fig file contains the graphics of your interface  myClassifier.m file contains all the code for the GUI

12 Steps for making Bayesian classifier using GUI 12  The.m file is where we attach the appropriate code to the callback of each component  we are primarily concerned only with the callback functions  You don’t have to worry about any of the other function types

13 What Is a Callback? 13  It is a function that you write and associate with a specific component in the GUI or with the GUI figure itself  It controls GUI or component behavior by performing some action in response to an event for its component  The event can be  a mouse click on a push button  menu selection  key press, etc.  There is a set of callbacks for each component and for the GUI figure itself.  For more information about callbacks you can visit this interested website http://www.mathworks.com/help/techdoc/creating_guis/f16-999606.html

14 Steps for making Bayesian classifier using GUI 14  Open up the.m file  In the MATLAB editor, click on the icon,which will bring up a list of the functions within the.m  Select drawBtn_Callback.

15 Steps for making Bayesian classifier using GUI 15  Using handles  Handles is a structure that contains all components in a figure including figure itself.  Texts, pushbutton, axes, … etc.  We can’t access any component without using handles

16 Steps for making Bayesian classifier using GUI 16  There are many important functions :  Set Set a value for the component property  Get Get the value of the component property  Str2num Convert from string to number  Num2str Convert from number to string

17 Examples 17  To get the value of pw1_text string:  p1=get(handles.pw1_text,’string’);  To set 20 to Mu1 string:  set(handles.Mu1_text,’string’,20);  Exercise:  Set a value of Mu1 string to Mu2 string

18 guidata function 18  One of important function in gui  It updates the value of the component and keep that variable in our memory-workspace  That’s important to be used in other callback functions.  We can achieve it by doing this: guidata(h,handles)  Generally speaking, we need to finish every callback function with it.

19 Dealing with inputs 19  In each text callback we should write these instructions: handles.m1=get(handles.m1,’string’); guidata(h, handles);  Where m1 is a variabe we define to store mean value that the user enterd in m1 text box  In any callback we can use it as handles.m1

20 20 Classify button callback Function classifyBtn_Callback(hObject, eventdata, handles)  m1=str2num(get(handles.m1,'string'));  m2=str2num(get(handles.m2,'string'));  s1=str2num(get(handles.s1,'string'));  s2=str2num(get(handles.s2,'string'));  p1=str2num(get(handles.p1,'string'));  p2=str2num(get(handles.p2,'string'));  x=str2num(get(handles.pattern,'string'));  Pxw1=NormalFun(x,m1, s1);  Pxw2=NormalFun(x,m2, s2);  Pw1x=Pxw1*p1/((Pxw1*p1)+(Pxw2*p2));  Pw2x=Pxw2*p2/((Pxw1*p1)+(Pxw2*p2));  %Now make a decision using the posteriors;  if (Pw1x > Pw2x)  rslt = sprintf('%d belongs to w1', x);  set(handles.result,'string',rslt)  else  rslt = sprintf('%d belongs to w2', x);  set(handles.result,'string',rslt)  end

21 21 Draw button callback  m1=str2num(get(handles.m1,'string'));  m2=str2num(get(handles.m2,'string'));  s1=str2num(get(handles.s1,'string'));  s2=str2num(get(handles.s2,'string'));  p1=str2num(get(handles.p1,'string'));  p2=str2num(get(handles.p2,'string'));  x=str2num(get(handles.pattern,'string') );  x1Max=m1+(4*s1); x1Min=m1-(4*s1);  x2Max=m2+(4*s2); x2Min=m2-(4*s2);  xMax=max(x1Max,x2Max); xMin=min(x1Min,x2Min);  x=xMin:0.1:xMax;  n=length(x); pxw1=zeros(1,n); pxw2=zeros(1,n); pw1x=zeros(1,n); pw2x=zeros(1,n);  for i=1:n  pxw1(i)=NormalFun(x(i),m1, s1); pxw2(i)=NormalFun(x(i),m2, s2);  end  for i=1:n  pw1x(i)=pxw1(i)*p1/((pxw1(i)*p 1)+(pxw2(i)*p2));  pw2x(i)=pxw2(i)*p2/((pxw1(i)*p 1)+(pxw2(i)*p2));  end  axes(handles.axes1);  plot(x,pw1x,'r- ',x,pw2x,'b');  axes(handles.axes2);  plot(x,pxw1,'r- ',x,pxw2,'b'); Function DrawBtn_Callback(hObject, eventdata, handles)

22 Launching the GUI 22  There are two ways to launch your GUI  through the GUIDE editor press the icon on the GUIDE editor  from the MATLAB command prompt type in the name of the GUI at the command prompt you don’t need to type the.fig or.m extension

23 23

24 References 24  Materials of this lab are prepared using:  http://blinkdagger.com/matlab/matlab-gui-graphical-user-interface-tutorial-for-beginners/  http://www.matrixlab-examples.com/callback-function.html  http://www.mathworks.com/help/techdoc/creating_guis/f16-999606.html


Download ppt "PATTERN RECOGNITION LAB 8 TA : Nouf Al-Harbi::"

Similar presentations


Ads by Google