From: Maxx on 29 Jun 2010 10:52 Hello all, Maybe there is a way I can use a pushbutton to execute this??? I've been working on a gui with GUIDE that extracts data from an excel sheet and places it into a cell array. The listbox then updates its contents based upon what item the user selects. The default value for listboxes is >1<, so the function skips the first array that I need to appear in the listbox and goes immeadiately to the last 'set' command. How can I stop this from happening? .... .... get(handles.figure1,'SelectionType'); if strcmp(get(handles.figure1,'SelectionType'),'open') set(handles.listbox1,'string',cellstr(substance)); substance_val=get(handles.listbox1,'value') if substance_val~=0 set(hObject,'string',data_excel(substance_val,:)); end end .... .... The default string in the listbox is "Pure Component". When I double click on it, the first string appears in the listbox with its corresponding data from a master array (data_excel ... 54X4). So it displays the name/row listed in column 1, gets the value(x) of the row, and displays the data in value(x) columns 2:4. This is good, I just need to be able to select something other than substance_val=1 (value=1). Any ideas? I'm not so good with callbacks or handles and the only examples I can find are with directories and "If" structures. Maxx
From: Walter Roberson on 4 Jul 2010 13:04 Maxx wrote: > if strcmp(get(handles.figure1,'SelectionType'),'open') > set(handles.listbox1,'string',cellstr(substance)); > substance_val=get(handles.listbox1,'value') > if substance_val~=0 > set(hObject,'string',data_excel(substance_val,:)); > end > end Why are you setting the listbox string _before_ getting the value? If the new string has fewer rows than the old one, are you certain the now out-of-range value will be preserved, or will it be clamped to the new maximum or will it be reset to 1? If you are going to fetch the Value of a list box, do it _before_ you change the content of the box, or else somehow wait for the user to make a selection after the box has been populated with the new strings. Also, consider adding a drawnow() to update the box contents.
|
Pages: 1 Prev: Calling dll-function with 'function pointers' as input Next: color coding isosurface plots |