I got some errors when I closed GUI. How do I fix it?

조회 수: 10 (최근 30일)
Aaron Abel
Aaron Abel 2020년 1월 15일
댓글: Cam Salzberger 2020년 1월 16일
I want to clear my error when I close my GUI
I do iteration to axes
while keepGoing
axes(handles.axes1); %#ok<LAXES>
a=imread('g4.jpeg');
imshow(a);
pause(5);
end
I got some errors when I closed my GUI
ss.JPG

답변 (1개)

Cam Salzberger
Cam Salzberger 2020년 1월 15일
Hey Aaron,
The error is likely because the code is trying to execute after you closed the figure window. Closing the figure destroys the axes, making the call to "axes" throw that error.
There are two simple fixes, and you can technically do both. The first is to add a "CloseRequestFcn" to the figure that changes a property that is checked by the while loop. An easier way is probably just to check that the axes are still valid before trying to use them, and dropping out of the loop if they're not valid:
while keepGoing && isvalid(handles.axes1)
...
end
Also, you can specify the axes to plot to directly in "imshow", using the 'Parent' name-value pair. So no need for the call to "axes". You may also consider updating "keepGoing" within the loop, as it currently doesn't seem like it will (unless it's a function call that checks some property or something). Finally, you can call "imshow" directly with the filename, so no need for a separate call to "imread", unless you use the results later.
-Cam
  댓글 수: 2
Aaron Abel
Aaron Abel 2020년 1월 15일
I've added
function untitled1_OpeningFcn(hObject, ~, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to untitled1 (see VARARGIN)
% Choose default command line output for untitled1
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes untitled1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
keepGoing=true;
axes(handles.axes1);
while keepGoing && isvalid(handles.axes1)
a=imread('g4.jpeg');
imshow(a);
pause(10);
end
I'm making infomation system that show an parking image to my parking users, I use the iteration, so the image can be updated. The image is from another GUI.
Your code works, but I find this errors
Capture.JPG
Cam Salzberger
Cam Salzberger 2020년 1월 16일
Remember to use imshow(a, 'Parent', handles.axes1), in case it becomes the non-active axes.
The OutputFcn is different from the OpeningFcn, so I can't be sure. I'd assume that the OpeningFcn is ending because you've closed the GUI, and then it tries to call the OutputFcn after that. It probably tries to get the handles struct using guidata, but that will probably return an empty array (or fail completely) if the figure is invalid.
If you don't need the output function, just remove the contents.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by