MATLAB Creating Graphical User Interfaces

(Barry) #1

9 Examples of GUIDE UIs


case 'Yes'
% If no name match was found create a new contact
Addresses(handles.Index).Phone = Current_Phone;
handles.Addresses = Addresses;
guidata(hObject,handles)
return
case 'Cancel'
% Revert back to the original number
set(handles.Contact_Phone,'String',Addresses(handles.Index).Phone)
return
end

Paging Through Entries — Prev/Next

By clicking the Prev and Next buttons you can page back and forth through the
entries in the address book. The Callback property of both push buttons are set to call
“Prev_Next_Callback” on page 9-14 in address_book.m.

The Prev_Next_Callback defines an additional argument, str, that indicates which
button, Prev or Next, is clicked. The Prev button Callback property includes 'Prev'
as the last argument. The Next button Callback string includes 'Next' as the last
argument. The value of str is used in case statements to implement each button's
function.

The Prev_Next_Callback gets the current index pointer and the addresses from
the handles structure and, depending on which button you click, the index pointer
decrements or increments and the corresponding address and phone number display. 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

function Prev_Next_Callback(hObject, eventdata, handles, str)
% Get the index pointer and the addresses
index = handles.Index;
Addresses = handles.Addresses;

% Depending on whether Prev or Next was clicked,
% change the display
switch str
case 'Prev'
% Decrease the index by one
i = index - 1;
% If the index is less than one then set
Free download pdf