User`s guide

10 Examples of GUIDE GUIs
is used in case statements to implem ent each button’s functionality (see
the code listing that follows).
Paging Forward or Backward
Prev_Next_Callback gets the current index pointer and the addresses f rom
the
handles structure a nd, depending on which button the user clicks, the
index pointer is decremented or incremented and the corresponding address
and phone number are displayed. The final step stores the new value for
the index pointer in the
handles structure and saves the updated structure
using
guidata.
Prev_Next_Callback Code Listing
function Prev_N ext_ Callback(hObject, e vent data,handles,str)
% Get the index pointer and the addresses
index = handles.Index;
Addresses = handles.Addresses;
% Depending on whether Prev or Next was cl icke d,
% change the display
switch str
case 'Prev'
% Decrease the index by one
i = index - 1;
% If the i ndex is less than one then set it equal to the index
% of the last element in the Addresses array
if i < 1
i = length(Addresses);
end
case 'Next'
% Increase the index by one
i = index + 1;
% If the i ndex is greater tha n the size of the array then
% point to the first item in the Addresses a rray
if i > len gth( Addresses)
i=1;
end
end
% Get the appropriate data for the index i n selected
Current_Name = Addresses(i).Name;
10-92