Problem with listbox in Matlab GUI.
2 views (last 30 days)
Show older comments
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 ?
0 Comments
Accepted Answer
Image Analyst
on 28 Sep 2013
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.
1 Comment
Masoud Daryoushi
on 3 Apr 2018
I have same problem, but you didn't propose a solution.
When I choose some elements and click on the push button ">" it works properly such as below:
But when I choose for example '60' and push button ">" the left list box disappears:
Here is the code in push button ">"
if true
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
currentSizes=get(handles.listbox2,'string');
selectedSizes = get(handles.listbox1, 'string');
selectedItems = get(handles.listbox1, 'value');
selectedSize = selectedSizes(selectedItems);
newList=[currentSizes;selectedSize];
N = cellfun( @str2double, regexp(newList, '\d+', 'match') );
[~,I] = sort(N);
newList = newList(I);
set(handles.listbox2,'string',newList);
newList2=selectedSizes;
newList2(selectedItems)=[];
N2 = cellfun( @str2double, regexp(newList2, '\d+', 'match') );
[~,I2] = sort(N2);
newList2 = newList2(I2);
set(handles.listbox1,'string',newList2);
end
More Answers (3)
Jan
on 27 Sep 2013
The warning message is clear: The values of the 'Min' and 'Max' properties define the listbox as a single selection control. Then exactly one element must be selected. If you want to select no or multiple elements, the distance between 'Min' and 'Max' must be greater than 1. Exmaple:
h = uicontrol('Style', 'listbox', 'String', {'1', '2'}); % Ok
pause(1);
set(h, 'Value', []); % Nothing selected, warning appears
pause(1)
set(h, 'Max', 2); % Listbox appears again
2 Comments
Jan
on 28 Sep 2013
@Jonasz: Ok, but because you did not show us the corresponding code at first, this guess would at least result in the same error message. The more details you post to describe a problem, the less time is wasted with wrong guesses.
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!