1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to write an interactive GUI in MATLAB

  1. Oct 5, 2010 #1
    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 se37tl.jpg 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
  2. jcsd
  3. Oct 5, 2010 #2
    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 !
  4. Oct 10, 2010 #3
    thanks that was quite useful
  5. Oct 14, 2010 #4
    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:
    Code (Text):
    >> 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:
    Code (Text):
    >> 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.

    Code (Text):
    >> 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
    Code (Text):
    >> 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
    Code (Text):
    >> 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:
    Code (Text):
    f = figure;
    a = axes;
    p = plot(1,1);
    now a has a child (the plot p) so if you run:
    Code (Text):
    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:
    Code (Text):
    >> 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
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook