why do i receive error while evaluating UIcontrol Callback?

load ('db');
Ftrain=db(:,1:2);
Ctrain=db(:,3);
for(i=1:size(Ftrain,1))
dist(i,:)=sum(abs(Ftrain(i,:)-Ftest)):
end
try to retrieve results from db but it shows "Error while evaluating UIcontrol Callback"

8 Comments

Please share the complete error message.
Please copy and paste all the red text from the command window.
Unrecognized function or variable 'im'.
Error in TestImage>btn_recog_Callback (line 116)
Ftest=FeatureStatistical(im);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in TestImage (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)TestImage('btn_recog_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Thank you. The error says that the variable "im" has not been defined before you try to use it here:
Ftest=FeatureStatistical(im);
Please share the complete code for the function btn_recog_Callback.
% --- Executes on button press in btn_recog.
function btn_recog_Callback(hObject, eventdata, handles)
% hObject handle to btn_recog (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%% Find the class the test image belongs
Ftest=FeatureStatistical(im);
%% Compare with the feature of training image in the database
db=db.mat;
load db;
Ftrain=db(:,1:2);
Ctrain=db(:,3);
for (i=1:size(Ftrain,1))
dist(i,:)=sum(abs(Ftrain(i,:)-Ftest));
end
m=find(dist==min(dist),1);
det_class=Ctrain(m);
if det_class == 13
R1 = 'qboissieri';
set(handles.txt_outName,'string',R1);
elseif det_class == 18
R2 = 'qfrainetto';
set(handles.txt_outName,'string',R2);
elseif det_class == 17
R3 = 'qellipsoidalis';
set(handles.txt_outName,'string',R3);
elseif det_class == 22
R4 = 'qilex';
set(handles.txt_outName,'string',R4);
end
guidata(hObject,handles);
If "im" is defined in another function, you have to do something to make it accessible in this function, e.g., put it in the handles structure.
This looks strange:
db=db.mat;
load db;
In the first line, db.mat extracts the field 'mat' of the struct called 'db'. The line
load db
is equivalent to the functional form:
load('db')
which adds '.mat' automatically. This might work by accident in your case. Most likely you mean:
db = 'db.mat';
load(db);
This looks similar, but has important differences.
After
Ftest=FeatureStatistical(im);
failed, because im is not a defined variable inside the current function, the line
db=db.mat;
will fail, because db is not a known variable also.

Sign in to comment.

Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products

Release

R2022b

Asked:

on 21 Jan 2023

Commented:

Jan
on 22 Jan 2023

Community Treasure Hunt

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

Start Hunting!