User`s guide

8 Programming a GUIDE GUI
Table CellSelectionCallback
Everytimetheuserselectsatablecell,thetablesCellSelectionCallback
fires. This happens whether table cells are editable or not. When cells are not
editable, users can drag across a range of cells to select them all. When cells
are editable, users can select more than one cell at a time using Shift+click or
Ctrl+click, but not by dragging. The indices for all currently selected cells are
returned in the
CellSelectionCallback eventdata structure. The callback
fires every time the selection changes, and new event data is passe d.
Slider
You can determine the current value of a slider from within its callback by
querying its
Value property, as illustrated in the following example:
function slider 1_Ca llback(hObject, eve ntda ta, handles)
slider_value = get(hObject,'Value');
% Proceed with callback...
The Max an d Min properties specify the slider’s maximum and minimum
values. T he slider’s range is
Max - Min.
List Box
When the list box Callback callback is triggered, the list box Va lue property
contains the index of the selected item, where
1 corresponds to the first item
in the list. The
String property contains the list as a cell array of strings.
This example retrieves the selected string. It assumes
listbox1 is the value
of the
Tag property. Note that it is necessary to convert the value returned
from the
String property from a cell array to a string.
function listbo x1_C allback(hObject, ev entd ata, handles)
index_selected = get(hObject,'Value');
list = get(hObject,'String');
item_selected = list{index_selected}; % Convert from cell array
% to string
You can also select a list item programmatically by setting the list box Value
property to the index of the desired item. For example,
set(handles.listbox1,'Value',2)
8-36