two listboxes in a GUI
显示 更早的评论
dear all
i'm trying to create a gui taht consits in 2 listboxes. The idea is load some data in the listbox 2 based in the selection on the lisbox 1. The data consist in 1:1:10 numbers. (10=as)
For this i create a script in the listbox 1 callback, that loads a file contained in a directory, the script read this file and put the contents on the listbox 2. However i have a problem setting the habdles of listbox 2.
here is the script in the callback of listbox 1 that must display the list in listbox 2.
%LISTBOX 1:
function listbox 1_Callback(hObject, eventdata, handles)
handles.output = hObject;
%store the selected station name from listbox as station (input for
%terracem scripts)
contents = cellstr(get(hObject,'String')); %returns stationslist contents as cell array
station_selection=char(contents{get(hObject,'Value')}) %returns selected item from stationslist
handles.statsel=station_selection; %selection of item in listbox 1 stored
%put profile names of profiles in next listbox/ new version
station=handles.statsel;
dirstations=handles.stationsdir;
%maindir=handles.maindir;
cd(dirstations)
cd(station)
sel=(handles.statsel);
load(sprintf('%s_swaths.mat',sel)); %load a file in the folder
as=nim
nameprof=(1:1:as);
%%%%%%%%%for instance, in this case the values of nim or as=10%%%%%%%
%%%%%here the program gives an error%%%%%%%%%%%%%%%%
set(handles.listbox2,'value', nameprof)
%save data
guidata(hObject, handles);
all the script seems to work good until i set the handles for the next listbox (listbox2), where the loaded data (nameprof =1:1:10) must be displayed.
here is the error:
Reference to non-existent field
'listbox2'.
Error in
Terracem_gui_v5b>stationslist_Callback
(line 793)
set(handles.listbox2,'value', nameprof)
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in Terracem_gui_v5b (line 42)
gui_mainfcn(gui_State,
varargin{:});
Error in
@(hObject,eventdata)Terracem_gui_v5b('stationslist_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
i dont know why i cannot set the callback for the listbox 2, someone have an idea to solve this....... thanks and thanx in advance
采纳的回答
更多回答(1 个)
Vishal Rane
2013-8-28
1 个投票
Check if the tag of the second listbox is 'listbox2'. Also confirm if the second listbox has been created when you are trying to access it.
类别
在 帮助中心 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!