two listboxes in a GUI
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuesta aceptada
David Sanchez
el 28 de Ag. de 2013
To set the list of numbers on the your list2, this has to be done by setting the 'String' property of list2. The list of elements to be inserted in list2 has to be a cell array.
nameprof=1:10;
set( handles.list2,'String',num2cell(nameprof) );
0 comentarios
Más respuestas (1)
Vishal Rane
el 28 de Ag. de 2013
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.
2 comentarios
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!