MATLAB: Problem with listbox in Matlab GUI.

guidelistboxMATLAB

Warning: single-selection listbox control requires that Value be an integer within String range Control will not be rendered until all of its parameter values are valid
I have 2 listbox. First listbox is show X coordinates and second one show the correspondind Y values for each X. eg. When I press X = 100 on the second listbox I see e.g Y = 100,101,102 ect. Sometimes when I press some values on Y listbox, and after that I change value on X listbox the Y listbox disappear and the error above shows.
Picture shows how it should work
Picture shows how it work when I press value higher than 100 on Y then when I press 442 X the Y listbox disappear.
I didn'y show the code because it's a lot of code and I think it's something wrong with listbox by itself. This is working properly. When I press 442 X it's working well but the error happens under specific conditions.
Any idea what might go wrong ?

Best Answer

Nothing is wrong with the listbox itself. There is something wrong in the callback for the X listbox, which you didn't want to show us. So you're either going to have to figure it out yourself of show us your code. In your callback for the X listbox, you're either
(A) doing something like loading the listbox for Y without the same number of entries it used to have like Y used to have 20 items in it and the selection was 18 and then you load it up with a cell array of 17 strings.
set(handles.listboxY, 'String', cellArrayOf17Strings);
Since the old (and current) value of 18 is more than the number of items now in the listbox (17), it won't be shown.
Or
(B) You're setting a value for the listbox for Y that is greater than the number of strings in it. For example Y has 20 items and then in your X callback you do
set(handles.listboxY, 'Value', 21);
Since 21 is more than the number of items in the Y listbox (20), it won't be drawn.
Bottom line, look for where you reference handles.listboxY in your callback for listboxX.
Related Question