amir nemat
amir nemat

Reputation: 105

Update Callback status in MATLAB GUI

I have developed a GUI interface in MATLAB. When I push a button search, I have seen the desirable result. However, when I change the textbox and push the search button again, it does not work and gives me following error:

Undefined function 'untitled2' for input arguments of type 'struct'.

Error in @(hObject,eventdata)untitled2('edit1_Callback',hObject,eventdata,guidata(hObject))


Error while evaluating uicontrol Callback

Undefined function 'untitled2' for input arguments of type 'struct'.

Error in @(hObject,eventdata)untitled2('pushbutton16_Callback',hObject,eventdata,guidata(hObject))


Error while evaluating uicontrol Callback

I must re-execute the all code! Is any way to repeatedly run the GUI?

As seen, when I change the Video ID to other number and push the search button, the results are not updated.

function pushbutton16_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton16 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%pathname='C:\Users\Dr Syed Abdul Rahman\Desktop\innovation final\video detail\';
string1 = get(handles.edit1,'UserData');
fName=strcat(cd,'\Video Detail\Video Detail',string1);
fid = fopen(fName);
if fid~=-1
 s{1} = fgetl(fid);
 s{2} = fgetl(fid);
 s{3} = fgetl(fid);
 s{4} = fgetl(fid);
 s{5} = fgetl(fid);
 s{6} = fgetl(fid);
 s{7} = fgetl(fid);

set(handles.text4,'Visible','On');
set(handles.edit1,'Visible','On','String',s{1})
set(handles.edit2,'Visible','On','String',s{2})
set(handles.edit3,'Visible','On','String',s{3})
set(handles.edit4,'Visible','On','String',s{4})
set(handles.edit5,'Visible','On','String',s{5})
set(handles.edit6,'Visible','On','String',s{6})
set(handles.edit7,'Visible','On','String',s{7})
set(handles.axes4,'Visible','On');
cd './Images';
A = imread(s{1});
axes(handles.axes4)
imshow(A);

else
 set(handles.text3,'Visible','On','String','File is not exist !') 
end

Upvotes: 0

Views: 2248

Answers (3)

Romain
Romain

Reputation: 340

You problem can come that you change your working folder when you use :

cd './Images';

A possible correction could be :

oldPath = cd('./Images'); % Return the path that you were before
A = imread(s{1});
axes(handles.axes4)
imshow(A);

cd(oldPath);  % Go back in the folder with all your functions

Upvotes: 0

chappjc
chappjc

Reputation: 30579

There are a lot of weird things going on in pushbutton16_Callback:

  • You don't need to keep setting 'Visible','on' for all your editboxes
  • get 'String' like amir nemat said, not 'UserData'
  • Use fullfile instead of strcat
  • Don't forget fclose(fid)!
  • Don't do cd './Images' in a callback unless you cd back but even then it's not a good idea, just imread into that path.
  • Do imshow(A,'Parent',handles.axes4) instead of axes(handles.axes4); imshow(A);

Also, you might want to rename your GUI to something other than untitled2. ;)

As for why you are getting the error, I don't know for sure, but I suspect when gui_mainfcn tries to feval your untitled2.m to run the callback, it is running something else. Check for other untitled2 MATLAB-executable files: which -all untitled2.

Upvotes: 1

sivanantham
sivanantham

Reputation: 33

Instead of this line "string1 = get(handles.edit1,'UserData');"

try this one string1 = get(handles.edit1,'String');

Upvotes: 2

Related Questions