next up previous contents
Next: Commonly Used Code Up: MATLAB GUI Tips Collated Previous: Introduction   Contents

Starting Point

Let us assume that a function $myfunction$ has been created and it takes a series of arguments (e.g., $arg1,$$arg2$ and so on). A call to this function will either produce a result (visual or numerical typically) or return data of some sort to the command-line (or command window). What is the difference between the two? Simply, the former makes the function a stand-alone list of commands that cannot be easily combined with other code. In the case of GUI's, these usually appear the appropriate entity to start off with. The exception is the case where our GUI should be used by another auxiliary application; but this case will not be considered here any further.

Let us illustrate with an example. The function draw_some_plot is is set to produce a plot and do nothing more. The code for such a file (draw_some_plot.m) may be:

plot(rand(10));
Now all we wish to do is to call this function from a graphical window which may, for example, contain just a button to invoke our function. The rather intuitive GUIDE (it can be simply started by typing in guide) that is based on Java, makes the placement of GUI elements an obvious step to follow. For information on the use of any GUI generation tool, see the relevant documentation and help files.

This then leads us to the concept of callbacks. These are functions that will be called once an event in some GUI occurs. Once a callback has been assigned to an object, the control flow of the program will be passed to the assigned callback. If a button has been assigned the callback named do_action, then once we press that button, the code under do_action will be executed. Going back to the example above, sensible code to put under this function will be just the statement:

draw_some_plot;
which will then draw the plot, assuming paths have been defined properly. We now have covered some dry and embarrassingly fundamental grounds. The next few section describe some of the interesting things that can be done to increase the functionality of the user interface quickly and wisely (in practice, I never got that far).


next up previous contents
Next: Commonly Used Code Up: MATLAB GUI Tips Collated Previous: Introduction   Contents
2004-05-19