# How to write an interactive GUI in MATLAB

by yaang
Tags: interactive, matlab, write
 P: 22 I'm supposed to write a matlab code where it calculates kinematics of a robot arm and plots it. But the plot is required to have a way of user entering different values and be able to change position of the robot. I think i can handle the kinematics behind it but i have no idea how to make an interactive gui like that in matlab. Basically i want to code something like this but mine is going to be much more simple of course. Can someone recommend me some reading on this subject so i can figure this out ? Thanks in advance
 P: 241 Hai to start with type "guide" in matlab command prompt. It will take you to creating new GUI that suits your application. You have to read "Creating GUI" in Matlab help first before proceeding !
 P: 22 thanks that was quite useful
P: 145

## How to write an interactive GUI in MATLAB

To give you a mini lesson on the way matlab handles figures (gui objects):

MATLAB deals with all graphics objects as Handles. If you dont know what that is, a Handle is a reference to a set of data. In the case of graphics objects in MATLAB, these handles are all simply double precision numbers.

To access or set any properties of any graphics, you have to use the get()/set() command, along with the handle to the graphics object you are referencing.

There are 3 "levels" of graphics objects in MATLAB:

Figure - the highest level. It is the window that any graphics objects you create go in. eg:
>> f = figure
creates an empty figure. f is now set to a handle to the figure you created. To see what kinds of properties figures have, use:
>> get(f)
Its a good idea to look at what this returns, so you can see what sorts of properties are stored in the figure handle. It stores data like the size of the figure, and other general properties.

Axes - The second level is the "child" of the figure, the axes. each axes is ALWAYS created in a figure (Matlab will create one if you create an axes without specifying a figure). The Axes is the "place" for plots, text, labels, and any other graphics object in MATLAB.

>> f = figure
a = axes;
This will create a figure then an axes in that figure. to see what sorts of things are stored in axes, use
>> get(a)
This will list all properties in the axes, its a good idea again to see whats there to understand what sort of things go into axes.

One thing to notice is the "parent" and "child" fields in axes/figures. In the code above, you created an axes in a figure. Now, if you run
>> child = get(f,'children');
% child==a will be true
it will return a handle to the axes you created - the same handle as a.

Graphics objectsThe last level of graphics objects are the actual graphics objects - plots, text, etc. Again, if you create a plot:
f = figure;
a = axes;
p = plot(1,1);
now a has a child (the plot p) so if you run:
child = get(a,'children')
child will point to the same plot as p. Again, it is a good idea to use get(p) to see what sort of things go in a graphics object.

Ive bored you enough with this stuff - it really is the most annoying part of matlab imo, but jsut remember you use get() and set for everything.

jsut realized I havent used set to set anything, heres a simple way to resize the figure f:
>> set(f,'position',[1,1,400,500]);
this will set the figure to begin at the [1,1] pixel on your screen and end at the [400,500] pixel (from the bottom left of your screen).

if makign an interactive GUI wuy will also need to look into callback functions, as they are important to any gui.

hope this essay didnt confuse you more

 Related Discussions Math & Science Software 8 Engineering, Comp Sci, & Technology Homework 4 Calculus & Beyond Homework 1 Math & Science Software 1 Math & Science Software 0