error in getting output using pushbutton

hi everyone..
im trying read a .fis file and evaluate it provided inputs from popupmenus,radiobuttons and textfield.i have written the following code.
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)
fismat=readfis('oralcancer_rulebase.fis');
out=evalfis([popupmenu2value popupmenu3value popupmenu4value num smokingvalue alcoholvalue gendervalue tumorsitevalue],fismat);
msgbox(sprintf('%d',out));
the following code is function of one of the popupmenu
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu2 (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 popupmenu2 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu2
contents1=get(handles.popupmenu2, 'String');
popupmenu2value=contents1{get(handles.popupmenu2, 'Value')};
switch popupmenu2value
case '1'
handles.value=1;
case '2'
handles.value=2;
case '3'
handles.value=3;
case '4a'
handles.value=4;
case '4b'
handles.value=5;
case 'x'
handles.value=6;
end
but im getting errors as follows
Undefined function or variable 'popupmenu2value'.
Error in testgui>pushbutton1_Callback (line 261)
out=evalfis([popupmenu2value popupmenu3value popupmenu4value num smokingvalue
alcoholvalue gendervalue tumorsitevalue],fismat);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in testgui (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)testgui('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
please provide me any solution. any kind of help will be appreciated

 采纳的回答

srinija - the variable popupmenu2value is local to the popupmenu2_Callback function only and so is not accessible from the pushbutton1_Callback function. If you want to use that value in the pushbutton callback then you can just determine it as you are doing already in the other callback. Try
function pushbutton1_Callback(hObject, eventdata, handles)
contents1=get(handles.popupmenu2, 'String');
popupmenu2value=contents1{get(handles.popupmenu2, 'Value')};
fismat=readfis('oralcancer_rulebase.fis');
% etc.
But then you will have the same problem with all the other variables that you are trying to use that haven't been defined in your pushbutton callback
out=evalfis([popupmenu2value popupmenu3value popupmenu4value num smokingvalue alcoholvalue gendervalue tumorsitevalue],fismat);
You will need to define these variables within the pushbutton callback if you wish to make use of them (or save them to the handles structure in the other callbacks and then access them here through the struct).

5 个评论

actually i cannot use popupmenu2value because it will have string value.so i think i should store handles.value in some other variable
im new to matlab please provide me solution
i have changed the code as follows
function alcohol_SelectionChangeFcn(hObject, eventdata)
handles=guidata(hObject);
alcoholvalue= get(eventdata.NewValue, 'Tag');
switch alcoholvalue
case 'yes'
handles.value=1;
case 'no'
handles.value=0;
end
handles.input6 =handles.value;
guidata(hObject,handles);
and callback function as
function pushbutton1_Callback(hObject, eventdata, handles)
fismat=readfis('oralcancer_rulebase.fis');
out=evalfis([handles.input1 handles.input2 handles.input3 handles.input4 handles.input5 handles.input6 handles.input7 handles.input8],fismat);
msgbox(sprintf('%d',out));
but im getting error as reference to nonexistent variable input6...
You have not guaranteed that alcohol_SelectionChangeFcn has ever been executed. A selection change function is not run when you initialize the ui object, only when the user selects something else.
thanks a lot Walter Roberson... i got the answer

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Entering Commands 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by