wait/retrieve data from another GUI
5 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Chandra Kurniawan
on 13 Jan 2012
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 Comment
Chandra Kurniawan
on 13 Jan 2012
First, don't forget to create the MAT file
tempImg = imread('cameraman.tif');
tempbw = tempImg;
save('temp.mat','tempImg','tempbw');
More Answers (1)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!