Top Banner
USING GUIDE By Sahil Potnis, VIT, Mumbai Creating a GUI in Matlab TUTORIAL : 1
13

GUI in Matlab - 1

May 07, 2015

Download

Technology

Sahil Potnis

A small Introduction to GUI designing in Matlab Using GUIDE.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: GUI in Matlab - 1

USING GUIDE

By Sahil Potnis, VIT, Mumbai

Creating a GUI in Matlab

TUTORIAL : 1

Page 2: GUI in Matlab - 1

By Sahil Potnis, VIT, Mumbai

STEP 1:

Open Matlab and type ‘guide’ in command window .

Guide stands for GUI Development Environment.

OR

You can select File-> new-> GUI.It is one and the same thing......

Page 3: GUI in Matlab - 1

By Sahil Potnis, VIT, Mumbai

Create New GUI

Page 4: GUI in Matlab - 1

By Sahil Potnis, VIT, Mumbai

Select a standard template from the list:Say for example : GUI with uicontrols

Save the GUI with a certain name –abc

This generates a abc.m file with the GUI code.

Now , you can play with the code.

Do not alter the initialization code up to line no:74

STEP 2:

Page 5: GUI in Matlab - 1

STEP 3:

By Sahil Potnis, VIT, Mumbai

All objects present within the GUI have their own tags.

Double click on an object to display it ‘s properties

Tag property will show you the existing tag of that object.

Callback and Create function of these are associated with this tag

Page 6: GUI in Matlab - 1

By Sahil Potnis, VIT, Mumbai

If you change the tag, and save the file automatically abc.m will be updated

(note-Do not alter the .m file to change the

tag, make changes in .fig file and save it).

Ta of your selected object is displayed at the right hand bottom corner of your .fig window.

Page 7: GUI in Matlab - 1

By Sahil Potnis, VIT, Mumbai

Now I will explain rest of basics using reference to the “Density * volume =Mass example”

Density, Volume are the Edit text boxes in which user can enter the values

Mass is the static text box in which answer is displayed.

Calculate and Reset are the two Pushbuttons while Units consists of two radio buttons

Page 8: GUI in Matlab - 1

By Sahil Potnis, VIT, Mumbai

STEP 4 :

Mutual Exclusivity of these radio buttons is preserved as they are embedded within a “button group’’ container.

A create function is essential when a value is to be obtained from the User

A callback function is essential when a value is to be assigned to a certain tag (static text) Or a certain object has to perform a specific task (pushbutton)

Page 9: GUI in Matlab - 1

By Sahil Potnis, VIT, Mumbai

Functions related to specific Objects can be viewed by using : View Callback

Page 10: GUI in Matlab - 1

By Sahil Potnis, VIT, Mumbai

You can further change the ‘calculate callback’ function as per your usage:

Even a function can be created within ‘calculate’ as follows:

Mass=fxname(handles.metricdata.density,handles.metricdat.volume)

Save a fxname.m file within the same folder and write the function within that file.

Page 11: GUI in Matlab - 1

By Sahil Potnis, VIT, Mumbai

Function [mass]=fxname(density,volume)%CODE%return

Make sure the parameter names and number of parameters within the function and main file match.

Page 12: GUI in Matlab - 1

By Sahil Potnis, VIT, Mumbai

EXPECTED OUTCOME :

You can now create a simple User Interface with User Input and perform certain operations on those input values....

Keep on trying new things.....Its the best way to

learn.!!

Watch out this space for tutorials on Matlab....

Page 13: GUI in Matlab - 1

Thank You

By Sahil Potnis, VIT, Mumbai

For further advanced Matlab programming visit : http://sahilpotnis.blogspot.in/

Or drop me a mail at : [email protected]