wait/retrieve data from another GUI

4 次查看(过去 30 天)
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