Why is GUI window closed after push the pushbutton?

조회 수: 1 (최근 30일)
Veronika
Veronika 2017년 2월 9일
편집: Adam 2017년 2월 14일
Dear all,
I would like to create GUI for image segmentation. But I have this problem: When I click on the pushbutton1 (Načtení skenu) to load the original image then entire GUI closes and no variables are saved in workspace.
I attach my GUI. Thank you for your answers.

답변 (1개)

Adam
Adam 2017년 2월 9일
편집: Adam 2017년 2월 9일
clc;
close all;
clear;
Why would you ever put these in a pushbutton callback?
close all is what closes your GUI, clear has the potential to do unspeakable things that will render your GUI useless if it did stay open (and serves no purpose since there are only 3 variables in your workspace at that point) and clc has no place in a GUI callback either.
  댓글 수: 7
Veronika
Veronika 2017년 2월 14일
I used the function
assignin('base', 'grayImage',grayImage );
for saving variables from GUI´s workspace to base workspace, but still there is an error for calling this variable (grayImage) after click on pushbutton2 (Histogram skenu). I attach my code and original image.
Jan
Jan 2017년 2월 14일
편집: Adam 2017년 2월 14일
@Veronika: Please read the link posted by Image Analyst again. It does not help to store the variable grayImage in the base workspace, because accessing it from the command window is not wanted. If you need this variable inside a GUI callback, you have to store it inside the GUI:
function pushbutton1_Callback(hObject, eventdata, handles)
...
handles.grayImage = grayImage;
guidata(hObject, handles);
end
function pushbutton2_Callback(hObject, eventdata, handles)
handles = guidata(hObject); % Get newest version
% The one from the inputs might be outdated - perhaps.
imhist(handles.grayImage, 256);
This is confusing and therefore it is one of the most frequently asked questions. Search in this forum for "share data between callbacks" to find hundreds of corresponding threads.
Please open a new thread for a new question in the future. Thanks.

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

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by