我正在使用Matlab GUI从数据库服务器更新弹出菜单。我能够更新工作区中的数据,但在我在回调中设置值后,它显示错误:
警告:'popupmenu'控件要求'Value'是String范围内的整数。在所有参数值都有效之前,不会呈现控件
我能够第一次设置弹出窗口,但是当我选择下一个弹出窗口时,它会显示错误。
{
function Load_Location_Callback(hObject, eventdata, handles)
global DatabaseConnection
%DatabaseConnection = connect2SEdB('Open');
global LoadFilter
% LoadFilter = { 'Category' 'Type' 'SubType' 'Make' 'Model' 'LoadLocation' 'SerialNumber'; ...
% 'ANY' 'ANY' 'ANY' 'ANY' 'ANY' 'ANY' 'ANY'; ...
% NaN NaN NaN NaN NaN NaN NaN };
%CurrentLoadSelection = queryLoadFilter( DatabaseConnection , LoadFilter);
global CurrentLoadSelection
dataLoadLocation = CurrentLoadSelection{2,6};% Imports the Load Location
val = get(handles.Load_Location,'Value');%Gets the value of specific column
global Load_Location_list
Load_Location_list = get(handles.Load_Location,'String');% Gets the Name of that Value
Selected_string1 = Load_Location_list{val};%Stores in Selected String
SelectedItem1 = val;%
% disp(Selected_string);
% disp(SelectedItem);
assignin('base','Load_Location_list',Load_Location_list{val});%Makes it in Workspace
x= strcmp(Load_Location_list{val}, dataLoadLocation(:,2));%Finds the Specific Selected Data
%disp(x)%Displays it in Command Center for CODER
New_Value_Load=(flip(transpose(dataLoadLocation(x,:))));
disp(New_Value_Load);
disp(LoadFilter(2:3,6))
LoadFilter(2:3,6)=New_Value_Load;
disp(LoadFilter)
% disp(dataLoadType(x,:))
assignin('base','LoadFilter',LoadFilter);
CurrentLoadSelection = queryLoadFilter(DatabaseConnection, LoadFilter);
assignin('base','CurrentLoadSelection',CurrentLoadSelection);
disp(CurrentLoadSelection)
guidata(hObject,handles);
%%Database Query to Load Location
% dataLoadLocation = CurrentLoadSelection{2,6};
% % disp(dataLoadLocation)
% % x=find(strcmp(Category_list{val}, dataLoadLocation(:,2)));
% % disp(x)
% % disp(dataLoadLocation(x,:))
% set(handles.Load_Location,'String',dataLoadLocation(:,2));
%%Database Query to Load Model
dataLoadModel = CurrentLoadSelection{2,5};
set(handles.Model,'String',dataLoadModel(:,2));
%%Database Query to Load Serial Number
dataLoadSerialNumber = CurrentLoadSelection{2,7};
set(handles.LocalSerialNumber,'String',dataLoadSerialNumber(:,2));
%%Database Query to Load Sub Type
dataLoadSubtype = CurrentLoadSelection{2,3};
set(handles.Sub_Type,'String',dataLoadSubtype(:,2));
%%Database Query to Load Category
dataLoadCategory = CurrentLoadSelection{2,1};
set(handles.Load_Category,'String',dataLoadCategory(:,2));
%Database Query to Load Type
dataLoadType = CurrentLoadSelection{2,2};
set(handles.Type,'String',dataLoadType(:,2));
%Database Query to Load Make
dataLoadMake = CurrentLoadSelection{2,4};
set(handles.Make,'String',dataLoadMake(:,2));
guidata(hObject,handles);
}
我正在使用数据库连接来调用更新 CurrentLoadSelection 的查询,然后更新剩余的弹出菜单。但是一旦我尝试选择其他弹出菜单选项,它就会显示上面提到的错误。
答案 0 :(得分:0)
当您重置弹出窗口Sub_Type
的String属性时,可能会发生此问题。
财产价值应满足以下条件:Value<=length(String)
。
为了避免重置String后出现问题,请执行以下操作:
set(handles.Sub_Type,'String',dataLoadSubtype(:,2));
str = get(handles.Sub_Type,'String');
if isempty(str)
error('Oops this should not happen!');
else
set(handles.Sub_Type,'Value',1);
end
请务必检查您是否在String
中放置了一个空数组