MATLAB: How to make a listbox that enters values into an edit box

MATLAB

I want to create a GUI in which a listbox controls the values put into an edit box.

Best Answer

The following example creates 2 uicontrols. One is a listbox, the other is an editable text box. The callBack from the listBox stores the listbox's String (s) and the listbox's value(v). The string is set by indexing into s with v.
function exampleGUI
editUI = uicontrol('Style','edit','tag','editbox');
listbox = uicontrol('style','listbox','units','normalized',...
'Position',[.1 .1 .4 .4],'String',{'a';'b';'c';'d'});
% Define listbox Callback property to update edit box
set(listbox, 'Callback', @(src, evt) listCallback(src, editUI));
end
function listCallback(src, editBoxHandle)
% Get current selection number
value = get(src, 'Value');
% Get entire string array.
strArr = get(src,'String');
% Index into string array to retrieve selection
selection = strArr{value};
set(editBoxHandle, 'String', selection);
end
For more information on how to create GUIs refer to the following URL:
<http://www.mathworks.com/access/helpdesk/help/techdoc/creating_guis/bqz79mu.html>