回调时的GUI

时间:2013-10-16 08:44:19

标签: matlab user-interface matlab-guide

我在matlab中开发了GUI界面。当我按下按钮时,其他按钮不再工作。 例如,我运行了一个函数,如果我想打开一个文件,打开文件按钮不再工作,并给我以下错误: 当我运行pushbutton16_Callback时,pushbutton15_Callback不再工作了。为什么?

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

1 个答案:

答案 0 :(得分:1)

我认为这是问题所在:

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

这段代码很奇怪。 while循环触发了我,因为它是代码卡住的主要嫌疑人。

然后我看到你的代码没有多大意义。你首先进行fgetl(fid) 10000次,然后进行sizS = sizS + 10000,然后你可能重复一次?

无论你的while循环内容如何,​​我都敢猜测停止条件ischar(tline)根本就不会被满足。