Creating Graphical User Interfaces    

Sharing Data Between Callbacks

You can share data between callbacks by storing it in the MATLAB handles structure. For example, to store data contained in a vector X in the handles structure, you

  1. Choose a name for the field of the handles structure where you want to store the data, for example, handles.my_data
  2. Set the field equal to X with the following command:
  3. Save the handles structure with the guidata function:

Here, hObject is the handle to the object that executes the callback.

To retrieve X in another callback, use the command

You can access the data in the handles structure in any callback because hObject and handles are input arguments for all the callbacks generated by GUIDE.

For more detailed information on the handles structure, see


  Opening Function Adding Code to the Opening Function