-1

I have developed GUI interface in matlab. When I press a button, other buttons are not working anymore. For example, I have run a function and if I wanted to open a file, the open file button is not working anymore and gives me following error : when I run pushbutton16_Callback, pushbutton15_Callback is not work anymore. why ?

Error in @(hObject,eventdata)untitled2('pushbutton15_Callback',hObject,eventdata,guidata(hObject)) 
Error while evaluating uicontrol Callback


function pushbutton15_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton15 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[filename pathname]=uigetfile({'*.*'},'Picture Selector');
fulpathname=strcat(pathname,filename);
set(handles.axes4,'Visible','On');
axes(handles.axes4)
imshow(fulpathname);
handles.pic=fulpathname;
info = imfinfo(fulpathname);
handles.format=info.Format;
guidata(hObject,handles);

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');
%cd ..;
fName=strcat(cd,'\Video Detail\Video Detail',string1);
%    fName=strcat(cd,'\Video Detail',(string1));
try
 fid = fopen(fName);
sizS = 10000;
lineCt = 1;
tline = fgetl(fid);
while ischar(tline)
s{lineCt} = tline;
lineCt = lineCt + 1;
%# grow s if necessary
if lineCt > sizS
   s = [s;cell(10000,1)];
   sizS = sizS + 10000;
end
tline = fgetl(fid);
end
%# remove empty entries in s
s(lineCt:end) = [];
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 'C:\Users\Dr Syed Abdul Rahman\Desktop\innovation final\Images';
cd './Images';
%str=strcat(string1);

A = imread('25');
axes(handles.axes4)
imshow(A);
%imshow('./video detail/1.jpg');
catch err
set(handles.text3,'Visible','On','String','File is not exist !') 
end
Ali Bodaghi
  • 71
  • 2
  • 10

1 Answers1

1

I think here is the problem:

sizS = 10000;
lineCt = 1;
tline = fgetl(fid);
while ischar(tline)
  s{lineCt} = tline;
  lineCt = lineCt + 1;
  %# grow s if necessary
  if lineCt > sizS
     s = [s;cell(10000,1)];
     sizS = sizS + 10000;
  end
  tline = fgetl(fid);
end

This code is very strange. The while loop triggered me as it is a prime suspect in code getting stuck.

Then I saw your code does not make much sense. You first do fgetl(fid) 10000 times, then you do sizS = sizS + 10000 and then you perhaps repeat this?

Regardless of the contents of your while loop, I dare guess that the stopping condition ischar(tline) is simply never met.

Dennis Jaheruddin
  • 21,208
  • 8
  • 66
  • 122
  • Dear Dennis thanks for interest. However, my question is I need my GUI run repetitively not for one times. I mean if I push a button, then other buttons are not work any more. – Ali Bodaghi Oct 16 '13 at 09:42
  • @AliBodaghi When you try to run the code in button 16, it will likely never end. As long as matlab is running one piece of code you will not be able to start another. Perhaps try simplyfing the code till a point where it does something trivial, but still allows you to push other buttons. Then you can expand from there and confirm the source of the problem. – Dennis Jaheruddin Oct 16 '13 at 09:47
  • Suppose that I develop a gui with 2 buttons A and B. when I push a button A, then other button B is not work anymore. Then, I must re-run the gui again for button B for working. – Ali Bodaghi Oct 16 '13 at 09:47
  • Dear @Dennis I have change the code with 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); But still I can not repeat my GUI due to following error. Undefined function 'untitled2' for input arguments of type 'struct'. Error in @(hObject,eventdata)untitled2('pushbutton8_Callback',hObject,eventdata,guidata(hObject)) Error while evaluating uicontrol Callback – Ali Bodaghi Oct 17 '13 at 02:10