필터 지우기
필터 지우기

Problem with listbox in Matlab GUI.

조회 수: 6 (최근 30일)
Jonasz
Jonasz 2013년 9월 27일
댓글: Masoud Daryoushi 2018년 4월 3일
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 ?

채택된 답변

Image Analyst
Image Analyst 2013년 9월 28일
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
Masoud Daryoushi
Masoud Daryoushi 2018년 4월 3일
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

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Jan
Jan 2013년 9월 27일
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
Jonasz
Jonasz 2013년 9월 28일
But I select only one value in both listboxes they are two different one.
Jan
Jan 2013년 9월 28일
@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.

댓글을 달려면 로그인하십시오.


Jonasz
Jonasz 2013년 9월 28일
This is my X callback. The function xy finds which Y are connected to which X .
function X_listbox_Callback(hObject, eventdata, handles)
% hObject handle to X_listbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns X_listbox contents as cell array
% contents{get(hObject,'Value')} returns selected item from X_listbox
id=get(hObject,'Value');
list=get(hObject,'String');
item_selected=str2double(list{id});
dire=get(handles.text_dir,'String');
yid=xy(item_selected,dire);
yid=yid';
set(handles.Y_listbox,'String',cellstr(num2str(yid)));

Jonasz
Jonasz 2013년 9월 28일
Ok I figure it out. The problem was to reset the Value of Y listbox to eg. one that all the values of X have.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by