wait/retrieve data from another GUI

조회 수: 2 (최근 30일)
Vinh
Vinh 2012년 1월 13일
Hi, my program uses a button in the main GUI to popup another GUI for settings. However, I want my main GUI to wait for that GUI to finish (i.e click OK button) and response immediately for the changes made by that GUI. Any idea how I can do that?

채택된 답변

Chandra Kurniawan
Chandra Kurniawan 2012년 1월 13일
Hi,
it is possible to do with small trick.
When passing data between GUIs, the idea is via MAT file.
I have 2 GUIs as shown in picture below :
In the first GUI, button 'Threshold' will execute second GUI.
In second GUI, you should threshold the image by changing the slider position and then click OK.
The thresholded image will appears in axes1 of first GUI.
Just try it. I will not explain more.
You should design the GUIs and here the code :
FIRST GUI
-------------------
function varargout = untitled(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1}), gui_State.gui_Callback = str2func(varargin{1}); end
if nargout, [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else, gui_mainfcn(gui_State, varargin{:}); end
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles.I = imread('cameraman.tif');
imshow(handles.I);
guidata(hObject, handles);
function varargout = untitled_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function pushbutton1_Callback(hObject, eventdata, handles)
handles.output = hObject;
tempImg = handles.I;
save('temp.mat','tempImg','-append');
uiwait(untitled2);
load('temp.mat');
handles.I = tempbw;
imshow(handles.I);
guidata(hObject, handles);
SECOND GUI
-------------------
function varargout = untitled2(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled2_OpeningFcn, ...
'gui_OutputFcn', @untitled2_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1}), gui_State.gui_Callback = str2func(varargin{1}); end
if nargout, [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else, gui_mainfcn(gui_State, varargin{:}); end
function untitled2_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
load temp.mat
handles.I = tempImg;
handles.bw = handles.I;
imshow(handles.I);
set(handles.slider1,'min',0,'max',1,'sliderstep',[.1 .1]);
guidata(hObject, handles);
function varargout = untitled2_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function slider1_Callback(hObject, eventdata, handles)
handles.output = hObject;
thresh = get(handles.slider1,'value');
handles.bw = im2bw(handles.I,thresh);
imshow(handles.bw);
guidata(hObject, handles);
function slider1_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
function pushbutton1_Callback(hObject, eventdata, handles)
handles.output = hObject;
tempbw = handles.bw;
save('temp.mat','tempbw','-append');
close(untitled2);
function pushbutton2_Callback(hObject, eventdata, handles)
close(untitled2);
I hope this clear.
  댓글 수: 1
Chandra Kurniawan
Chandra Kurniawan 2012년 1월 13일
First, don't forget to create the MAT file
tempImg = imread('cameraman.tif');
tempbw = tempImg;
save('temp.mat','tempImg','tempbw');

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

추가 답변 (1개)

Vinh
Vinh 2012년 1월 15일
it worked bro. Cheers.
  댓글 수: 1
Vinh
Vinh 2012년 1월 15일
by the way, my processed images are extremely big (~4500 x 3000) so it is better to save the setting info into .mat rather than saving images into .mat

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

카테고리

Help CenterFile Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by