Matlab : GUI

This chapter will discuss about using Matlab fuzzy toolbox. Suppose you already have data and want to process the data using fuzzy. In general, you should follow this block diagram.

Data -> Pre process -> Decision Function

To start the tutorial, we will create simple GUI to simplify our work.

Write guide command in command window and save it. It will create two files which are one .m file and one .fig file. For example we save with name “Workshop2” so it will create two file Workshop2.fig and Workshop2.m in your folder.

> guide

untitled-1

Drag the Edit Text, Static Text, and Push Button on the left to the figure. The appearance become like this.

untitled-21

Now we will learn how to get input from Edit Text when we push the Push Button.

Go to your Push Button code in Workshop2.m and write this code.

untitled-33

Now run the figure and write anything in the Edit Text. For example we write “TEST” in the Edit Text and press the Push Button then the text will show in Static Text as “TEXT”.

untitled-31

Now we will use custom function in the GUI. This function will detect odd or even based on the input value in Edit Text and show it on Static Text.

function result = detectoddeven(input)

if (mod(input, 2) == 0)

result = ‘EVEN’;

else

result = ‘ODD’;

end

end

Save it to detectoddeven.m and in the Workshop2.m under Push Button section we write this code.

untitled-35

If we run the program and set input with value 6666, the program will detect the value as “even”

untitled-34

Now we want to create menu in the GUI using menu editor.

untitled-38

We will create if Menu -> SubMenu is clicked then the GUI will close with this code

untitled-37

And the result

untitled-36

We want to browse through the explorer and get an item from it to show the filename on Static Text. First we create one more push button and name it “BROWSE” and in the Workshop2.m under pushbutton2 section we add this code

untitled-39

And the browse dialog will be

untitled-40

When we choose a file and click Open then the filename will be shown in Static Text

untitled-41