two listboxes in a GUI

4 visualizzazioni (ultimi 30 giorni)
Jules Ray
Jules Ray il 26 Ago 2013
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

Risposta accettata

David Sanchez
David Sanchez il 28 Ago 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) );

Più risposte (1)

Vishal Rane
Vishal Rane il 28 Ago 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 Commenti
Jules Ray
Jules Ray il 28 Ago 2013
Thanks.. i realize that i didnt save the .fig file, only the .m ... :p
Jules Ray
Jules Ray il 28 Ago 2013
i have been trying again but the problem continues. THe listbox2 is created and the tag is correct, and all seems to be in order but this line dosent work:
set(handles.listbox2,'String',num2cell(af));
is ok to set the handles of the listbox2 into the callback of listbox1? i'm trying to load data in the listbox2 by selecting data in listbox1, is possible to do that? i mean, by clicking an item in listbox1 a set of string (1:10) will be loaded into the listbox2.
what i'm doing bad?

Accedi per commentare.

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by