Related
Can anyone please tell me how can i make my main app open a secondary app which will capture some values and then send them back to my main app?
I'm aware that this issue is tackled in app designer documentation, but I have been unable to implement those steps successfully. Also, I tried to run the example but Matlab says the file doesn't exists. If anyone could please share that example it would be also very helpful.
I have never tried to implement this on my own, but I often wandered myself how I could accomplish this if facing a complex apps architecture.
Actually, if you instantiate two GUIs in the same script/function, or if you have one GUI creating another GUI inside one of its functions, the simplest way would be to play with function handles. For example, the first GUI can pass a function handle defined among its functions to the target GUI's constructor and, this way, the target GUI can invoke it in order to modify the first GUI's data and/or properties when necessary.
The standard approach, anyway, which is considered as a best practice, works as follows. Let's assume that you have two GUIs named G1 and G2 and that they are distinct (you are not running two instances of the same GUI). If they are both visible (HandleVisibility set to on) and they both have a Tag identifier defined (G1 and G2 in our example), you can search for them within the Matlab "workspace". Hence:
% This is a G2 event handler
function pushbutton1_Callback(hObject, eventdata, handles)
g1_h = findobj('Tag','G1');
if (~isempty(g1_h))
% get all data associated to G1
g1_data = guidata(g1_h);
% modify a G2 object based on a G1 object
set(handles.MyTextBox,'String',get(g1_data.MyEditBox,'String'));
end
end
MATLAB's App Designer generates class-based GUI's rather than GUIDE's function-based GUIs. The advantage of this approach is that we can pass the GUIs around as objects rather than having to get creative with things like function returns or searching for objects by tag.
Here's a simple programmatic example that illustrates one approach to this concept. The main figure window opens a secondary prompt window, which provides two inputs. When the prompt window is closed, the primary GUI prints the input values to the command window and exits.
The main window:
classdef mainwindow < handle
properties
mainfig
butt
end
methods
function [self] = mainwindow()
% Build a GUI
self.mainfig = figure('Name', 'MainWindow', 'Numbertitle', 'off', ...
'MenuBar', 'none', 'ToolBar', 'none');
self.butt = uicontrol('Parent', self.mainfig, 'Style', 'Pushbutton', ...
'Units', 'Normalized', 'Position', [0.1 0.1 0.8 0.8], ...
'String', 'Push Me', 'Callback', #(h,e) self.buttoncallback);
end
function buttoncallback(self)
tmpwindow = subwindow(); % Open popupwindow
uiwait(tmpwindow.mainfig); % Wait for popup window to be closed
fprintf('Parameter 1: %u\nParameter 2: %u\n', tmpwindow.parameter1, tmpwindow.parameter2);
close(self.mainfig);
end
end
end
The sub window:
classdef subwindow < handle
properties
mainfig
label1
box1
label2
box2
closebutton
parameter1
parameter2
end
methods
function [self] = subwindow()
% Build a GUI
self.mainfig = figure('Name', 'SubWindow', 'Numbertitle', 'off', ...
'MenuBar', 'none', 'ToolBar', 'none');
self.label1 = uicontrol('Parent', self.mainfig, 'Style', 'text', ...
'Units', 'Normalized', 'Position', [0.4 0.7 0.2 0.05], ...
'String', 'Parameter 1');
self.box1 = uicontrol('Parent', self.mainfig, 'Style', 'edit', ...
'Units', 'Normalized', 'Position', [0.4 0.6 0.2 0.1], ...
'String', '10');
self.label2 = uicontrol('Parent', self.mainfig, 'Style', 'text', ...
'Units', 'Normalized', 'Position', [0.4 0.4 0.2 0.05], ...
'String', 'Parameter 2');
self.box2 = uicontrol('Parent', self.mainfig, 'Style', 'edit', ...
'Units', 'Normalized', 'Position', [0.4 0.3 0.2 0.1], ...
'String', '10');
self.closebutton = uicontrol('Parent', self.mainfig, 'Style', 'Pushbutton', ...
'Units', 'Normalized', 'Position', [0.4 0.1 0.2 0.1], ...
'String', 'Close Window', 'Callback', #(h,e) self.closewindow);
end
function closewindow(self)
% Drop our input parameters into this window's properties
self.parameter1 = str2double(self.box1.String);
self.parameter2 = str2double(self.box2.String);
% Close the window
close(self.mainfig);
end
end
end
I have a problem with my MATLAB GUI.
I am not using GUIDE so I am self coding everything for my GUI. I have a Main which generates the a first panel of the GUIDE. This panel contains a button which can create other 2 panels through its related callback function. In the other 2 panels it is possible to do other operations calling other callback functions. One of these operations is to create 2 new static texts and 2 new editable texts. I have problems in updating the handles related to those editable texts. More precisely I am not able to retrieve the value of their string once the text is edited and the callback functions of the last 2 panels are called again.
Attached is the code where all the callback functions of the GUI are:
%% server_selected callback function
function server_selected(hObject, eventdata, handles)
%UNTITLED8 Summary of this function goes here
% Detailed explanation goes here
% Get server version and run LaunchCDbQuery
servers = get(handles.server_popup, 'String');
serverVersion = servers{get(handles.server_popup, 'Value')};
[Day] = LaunchCDbQuery(serverVersion);
assignin('base', 'Day', Day)
% Update current outing on GUI
set(handles.outing_text, 'String', strcat(Day.date, Day.DocumentKey))
% Tool description
% Create panel for the tool description
handles.description_panel = uipanel('Title', 'Tool description',...
'units', 'normalized',...
'position', [0.675, 0.025, 0.3, 0.9]);
% Create items inside the panel for the tool description
% Function heading
handles.funheading_text = uicontrol('Parent', handles.description_panel,...
'Style', 'text',...
'units', 'normalized',...
'position', [0, 0.7, 1, 0.2],...
'String', 'Please choose a tool and click description to obtain the tool''s heading and description.',...
'HorizontalAlignment', 'left');
% Function description
handles.description_text = uicontrol('Parent', handles.description_panel,...
'Style', 'text',...
'units', 'normalized',...
'position', [0, 0.05, 1, 0.6],...
'HorizontalAlignment', 'left');
% Tool selection
% Create panel for the tool selection
handles.tool_panel = uipanel('Title', 'Tool selection',...
'units', 'normalized',...
'position', [0.35 0.025 0.3 0.9]);
% Create items inside the panel for the tool selection
% Text
handles.tool_text = uicontrol('Parent', handles.tool_panel,...
'Style', 'text',...
'units', 'normalized',...
'position', [0 0.7 1 0.2],...
'String', 'Please choose a tool to perform a piece of analysis.',...
'HorizontalAlignment', 'left');
% Popup
handles.tool_popup = uicontrol('Parent', handles.tool_panel,...
'Style', 'popup',...
'units', 'normalized',...
'position', [0.2 0.25 0.6 0.4],...
'String', {'plotmaptg'; 'TestReview'});
% Input variables panel
handles.varin_panel = uipanel('Parent', handles.tool_panel,...
'Title', 'Type input variables',...
'units', 'normalized',...
'position', [0, 0, 1, 0.3]);
% Description push
handles.tool_push_description = uicontrol('Parent', handles.tool_panel,...
'Style', 'pushbutton',...
'units', 'normalized',...
'position', [0.05 0.4 0.4 0.1],...
'String', 'Description',...
'callback', {#tool_description, handles});
% Ok push
handles.tool_push_ok = uicontrol('Parent', handles.tool_panel,...
'Style', 'pushbutton',...
'units', 'normalized',...
'position', [0.51 0.4 0.4 0.1],...
'String', 'Ok',...
'callback', {#tool_selected, handles, Day});
% Update guidata
guidata(hObject, handles)
end
%% tool_description callback function
function tool_description(hObject, eventdata, handles)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
% Call handles function
handles = tool_description_handles(handles);
% Update guidata
guidata(hObject, handles)
end
function newHandles = tool_description_handles(handles)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
% Get tool name
tools = get(handles.tool_popup, 'String');
tool_selected = tools{get(handles.tool_popup, 'Value')};
% Open tool .m file
fid = fopen(strcat(tool_selected, '.m'), 'r');
% Read .m file to find function description and save it
line = fgets(fid);
heading = line;
while isempty(regexp(line, '%', 'ONCE'))
line = fgets(fid);
end
description = [];
while ~isempty(regexp(line, '%', 'ONCE'))
description = strcat(description, line(regexp(line, '%', 'ONCE'):end));
line = fgets(fid);
end
description(regexp(description, '%')) = [];
fclose(fid);
% Set descritption found to the description handle
set(handles.funheading_text, 'String', heading);
set(handles.description_text, 'String', description);
% Find the input variables needed to run the tool
global inputs varout
[varin, varout] = get_arg_names(strcat(pwd, '\Tools\', tool_selected, '.m'));
inputs = cell(1, length(varin{1,1}));
for i = 1:length(varin{1,1})
% Input variable text
handles.varin_text(i) = uicontrol('Parent', handles.varin_panel,...
'Style', 'text',...
'units', 'normalized',...
'position', [0, 1-i*(1/length(varin{1,1})), 0.45, 1/length(varin{1,1})],...
'String', varin{1,1}{i,1},...
'HorizontalAlignment', 'left');
% Input variables editable text
handles.varin_edit(i) = uicontrol('Parent', handles.varin_panel,...
'Style', 'edit',...
'units', 'normalized',...
'position', [0.55, 1-i*(1/length(varin{1,1})), 1, 1/length(varin{1,1})],...
'HorizontalAlignment', 'left',...
'callback', {#varin_callback, handles});
end
% Save handles
newHandles = handles;
end
function varin_callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Save in the main workspace the input variables
global inputs
for i = 1:length(inputs)
if isempty(inputs{1,i})
inputs{1,i} = get(hObject,'String');
break
end
end
end
%% tool_selected callback function
function tool_selected(hObject, eventdata, handles, Day)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
% Get tool name
tools = get(handles.tool_popup, 'String');
tool = tools{get(handles.tool_popup, 'Value')};
% fh = str2func(tool);
% Get tool inputs and outputs
global inputs varout
% Run the tool
if ~isempty(varout)
expression = strcat('out = ', tool, '(');
else
expression = strcat(tool, '(');
end
for i = 1:length(inputs)
if ~isempty(inputs{1,i})
expression = strcat(expression, inputs{1,i}, ',');
else
break
end
end
expression(end) = ')';
eval(expression)
% Update guidata
guidata(hObject, handles)
end
I have tried using guidata(hObject, handles) at the end of each function but it did not work out. As now I am using global variables to avoid the problem but I would really like to just update the handles as they are modified.
When providing an input variable to a callback function, the variable that is passed when you invoke the callback is that variable as it exists when the callback is defined. MATLAB does not know to update these inputs as you modify guidata.
You can see this with the following example:
function testcode
h.mf = figure('Menubar', 'none', 'NumberTitle', 'off', 'ToolBar', 'none');
h.lb = uicontrol('Parent', h.mf, 'Style', 'Listbox', ...
'Units', 'Normalized', 'Position', [0.1 0.5 0.4 0.4] ...
);
h.b1 = uicontrol('Parent', h.mf, 'Style', 'pushbutton', ...
'Units', 'Normalized', 'Position', [0.1 0.1 0.4 0.3], ...
'String', 'Pass handles','Callback', {#button1push, h});
h.b2 = uicontrol('Parent', h.mf, 'Style', 'pushbutton', ...
'Units', 'Normalized', 'Position', [0.5 0.1 0.4 0.3], ...
'String', 'Use GUIdata', 'Callback', #button2push);
guidata(h.mf, h);
makepanel(h.mf);
end
function makepanel(mf)
h = guidata(mf);
h.panel = uipanel('Parent', h.mf, 'Title', 'A Panel', ...
'Units', 'Normalized', 'Position', [0.5 0.5 0.4 0.4] ...
);
guidata(h.mf, h);
end
function button1push(~, ~, h)
h.lb.String = fieldnames(h);
end
function button2push(hObj, ~)
h = guidata(hObj);
h.lb.String = fieldnames(h);
end
Push each button and look at the output in the listbox. You can see that the change to h made in makepanel is not shown when you hit Button 1.
Rather than passing handles as a callback input (like Button 1 above), call guidata with an output at the beginning of your function to obtain the most current version of handles. If your callback makes changes to the handles structure, call guidata again to store these changes for other callbacks.
I want to write a GUI program in Matlab and make 3 sliders on it with uicontrol and then write callbacks to use their 3 values in one command. I found a way to write a function for one slider as you can see in my program. Can you help me how use these 3 callbacks? (I use R2014a)
sld = uicontrol('Style', 'slider',...
'Min',0,'Max',255,'Value',0,...
'Position', [400 20 120 20],...
'Callback', #Blue);
sld = uicontrol('Style', 'slider',...
'Min',0,'Max',255,'Value',0,...
'Position', [400 60 120 20],...
'Callback', #Green);
sld = uicontrol('Style', 'slider',...
'Min',0,'Max',255,'Value',255,...
'Position', [400 100 120 20],...
'Callback', #Red);
function Red(source,~)
R = get(source,'Value');
end
function Green(source,~)
G = get(source,'Value');
end
function Blue(source,~)
B = get(source,'Value');
end
RGB = cat(3,R,G,B); %??????
Error: Undefined function or variable "R".
Persistent data must be stored somewhere that's accessible to the callback function. One common technique is to use the parent figure's UserData field. In the example above, once a slider has been moved, the current colour can be found in the RGB field of figure fh's UserData. Also, here only one callback is used, and the UI item is identified via its Tag.
fh = figure(1);
clf
%// Initialize figure's UserData
set(fh, 'UserData', struct('RGB', [0 0 0]));
sld_b = uicontrol('Style', 'slider',...
'Min',0,'Max',255,'Value',0,...
'Position', [400 20 120 20],...
'Callback', #colourHandler, 'Tag', 'blue');
sld_g = uicontrol('Style', 'slider',...
'Min',0,'Max',255,'Value',0,...
'Position', [400 60 120 20],...
'Callback', #colourHandler, 'Tag', 'green');
sld_r = uicontrol('Style', 'slider',...
'Min',0,'Max',255,'Value',255,...
'Position', [400 100 120 20],...
'Callback', #colourHandler, 'Tag', 'red');
%// This is in a separate file, colourHandler.m
function colourHandler(source, ~)
%// Find which slider triggered us
if strcmpi(get(source, 'Tag'), 'red')
ind = 1;
elseif strcmpi(get(source, 'Tag'), 'green')
ind = 2;
else
ind = 3;
end
%// update UserData
ud = get(get(source, 'Parent'), 'UserData');
ud.RGB(ind) = get(source, 'Value');
set(get(source, 'Parent'), 'UserData', ud);
end
Alternatively you can just store the handles of your graphics objects and use those to obtain the values in other functions.
For example:
function testcode
% Initialize sample GUI
h.fig = figure( 'MenuBar', 'none', 'ToolBar', 'none');
h.sld(1) = uicontrol( ...
'Parent', h.fig, ...
'Style', 'slider',...
'Min', 0, 'Max', 255, 'Value', 0, ...
'Units', 'Normalized', 'Position', [0.1 0.65 0.4 0.1], ...
'Tag', 'Red' ...
);
h.sld(2) = uicontrol( ...
'Parent', h.fig, ...
'Style', 'slider', ...
'Min', 0, 'Max', 255, 'Value', 0, ...
'Units', 'Normalized', 'Position', [0.1 0.45 0.4 0.1], ...
'Tag', 'Green' ...
);
h.sld(3) = uicontrol( ...
'Parent', h.fig, ...
'Style', 'slider', ...
'Min', 0, 'Max', 255, 'Value', 255, ...
'Units', 'Normalized', 'Position', [0.1 0.25 0.4 0.1], ...
'Tag', 'Blue' ...
);
% Use an axes object as a color display box
% Get starting RGB values for the color display, normalized so 0 <= x <= 1
startRGB = [get(h.sld(1), 'Value'), get(h.sld(2), 'Value'), get(h.sld(3), 'Value')]/255;
h.ax = axes( ...
'Parent', h.fig, ...
'Units', 'Normalized', 'Position', [0.6 0.36 0.3 0.3], ...
'XTickLabels', '', 'YTickLabels', '', ...
'Color', startRGB ...
);
% Need to set callback after all our elements are initialized
nsliders = length(h.sld);
set(h.sld, {'Callback'}, repmat({{#slidercallback, h}}, nsliders, 1));
end
function slidercallback(~, ~, h)
% Update background color of our axes object every time the slider is updated
RGB = [get(h.sld(1), 'Value'), get(h.sld(2), 'Value'), get(h.sld(3), 'Value')]/255;
set(h.ax, 'Color', RGB');
end
When callbacks execute they are passed 2 inputs by default, the invoking object and a structure of event data. As explained in the callback documentation, you can pass additional inputs to your callback by wrapping everything into a cell array. One thing to note is that the value of your variable being passed to the callback is its value as it exists when you define the callback. In other words, if we set the callback for our sliders at the same time we create them, when the callback for Red is fired h will only contain a handle to our figure, when the callback for Green is fired h will contain a handle to our figure and to the Red slider, and so on.
Because of this, you will see I have defined the callbacks once we have initialized all of our graphics objects. Using the curly brackets to set properties of multiple objects is explained in MATLAB's documentation for set. I use repmat so the size of the cell array is the same size as our array of slider objects.
I have a displayable image which I load via uigetfile. I want to allow the user to choose which portion of the image he wants to load by keying in the pixel coordinates of the top-left pixel and the bottom-right pixel into editable boxes. The problem is that I'm having some serious issues with the handles structure used to store data and don't quite understand how to use it.
Here is my code. I can easily load the 4 pixels in the topleft corner of the image (that's the default setting), but I fail to load anything else when the editable box values are changed. Is there something I'm missing here?
function mygui
%%
%Initialise GUI and set up editable boxes and push buttons
f = figure('Visible', 'off', 'Position', [360 500 450 285]);
handles.data.topleft1 = 1; %x-axis position of topleft pixel
handles.data.topleft2 = 1; %y-axis position of topleft pixel
handles.data.botright1 = 2; %x-axis position of bottom right pixel
handles.data.botright2 = 2; %y-axis position of bottom right pixel
hloader = uicontrol('Style', 'pushbutton', 'String', 'Load File', 'Position', [8 5 50 20], 'Callback', {#loadbutton_Callback, handles});
htopleft1 = uicontrol('Style', 'edit', 'String', handles.data.topleft1, 'Position', [25 40 15 10], 'Callback', {#topleft1_Callback, handles});
htopleft2 = uicontrol('Style', 'edit', 'String', handles.data.topleft2, 'Position', [40 40 15 10], 'Callback', {#topleft2_Callback, handles});
hbotright1 = uicontrol('Style', 'edit', 'String', handles.data.botright1, 'Position', [25 30 15 10], 'Callback', {#botright1_Callback, handles});
hbotright2 = uicontrol('Style', 'edit', 'String', handles.data.botright2, 'Position', [40 30 15 10], 'Callback', {#botright2_Callback, handles});
set([f, hloader, htopleft1, htopleft2, hbotright1, hbotright2], 'Units', 'normalized');
movegui(f, 'center')
set(f, 'Visible', 'on', 'toolbar', 'figure');
%%
%Loader pushbutton
function loadbutton_Callback(source, eventdata, handles)
[filename, pathname, filterindex] = uigetfile('*.jpg'); %Choose mario picture here from the directory you downloaded it from
picture = imread(strcat(pathname,filename));
topleft1 = handles.data.topleft1;
topleft2 = handles.data.topleft2;
botright1 = handles.data.botright1;
botright2 = handles.data.botright2;
picture = picture([topleft1:botright1], [topleft2:botright2], :); %Trim picture dimensions according to editable box inputs
imagesc(picture)
end
%%
%Editable boxes
function topleft1_Callback(source, eventdata, handles)
%Get new input from editable box; Save it into guidata handles structure thingy
topleft1 = str2double(get(source, 'String'));
handles.data.topleft1 = topleft1;
guidata(source, handles)
end
%(Repeat 3 more times for topleft2, botright1 and botright2)
end
And as usual, here's the picture which I'm trying to trim:
(source: gawkerassets.com)
I can suggest a solution with some changes that might be not as efficient, bu they'll work. I would do this kind of passing data between callbacks simply using the fact that Your whole GUI is a nested function, so all the callbacks can acces handles without even running the guidata function:
Do achieve this just change the way boxes are calling their callbacks from
(... 'Callback', {#topleft1_Callback, handles})
to:
(... 'Callback', #topleft1_Callback)
Now adjust arguments taken by Your callbacks, so the don't take three but two:
function myCallback(source,eventdata)
although none of those will be used, so You could simply write:
function myCallback(~,~)
as You MATlab will probably suggest. And You don't need the
guidata(source, handles);
line in any of Your callbacks anymore, since handles can be accesed anyway just by its name.
I have been trying to program a GUI which is supposed to receive one variable as an input and perform several operations that generate another variable.
The GUI will have one pushbutton that closes the GUI.
I am not (and don't want) to use GUIDE.
Below, I provide a minimal working example of a GUI that simply adds one to the input variable. The "Done" push button closes the GUI but I cannot find out a way to export the variable to the workspace.
% Is this the correct way to initialize the function for what I am trying to do?
function outputVariable = exampleGUI(inputVariable)
% Initialize main figure
hdl.mainfig = figure();
% Add Button
hdl.addPushButton = uicontrol(hdl.mainfig, 'Units', 'normalized',
'Position', [0.05 0.6 0.3 0.25], 'String',
'Add One', 'Callback', #addOne);
% Done Button
hdl.donePushButton = uicontrol(hdl.mainfig, 'Units', 'normalized',
'Position', [0.65 0.6 0.3 0.25], 'String',
'Done', 'Callback', #done);
% Static text
hdl.sliceNoText = uicontrol(hdl.mainfig, 'Style', 'text',
'Fontsize', 16, 'Units', 'normalized',
'Position', [0.35 0.2 0.3 0.25]);
function addOne(~, ~, ~)
inputVariable = inputVariable + 1; % add one to the current inputVariable
set(hdl.sliceNoText, 'String', num2str(inputVariable)); % change static text
newVariable = inputVariable; % new variable to be exported
end
function done(~, ~, ~)
delete(hdl.mainfig); % close GUI
end
end
I would like to do something like:
In the workspace:
outputVariable = exampleGUI(inputVariable)
And after adding one to the input variable a certain number of times, I would push the "Done" pushbutton and the GUI would be closed and the workspace would contain both inputVariable and the outputVariable.
Thanks a lot.
fnery
This is an example of what you can do. There are a ton of things you can do to make this work with the functionality you want. Typically I don't like to have any variables in the whole function's workspace besides the inputs and outputs as well as the guihandles. I use setappdata and getappdata to store other variables and have them accessible to callbacks. This is up to you, but the following is an example of how you can make your simple gui work. The CloseRequestFcn allows you the handle what happens if the user just closes the gui. Hope this helps. In addition, the waitfor prevents the function from returning until the function is closed. If you want, you can also set the figure's 'WindowStyle' property to 'modal' to force the user to put an input before he can close the gui.
function outputVariable = exampleGUI(inputVariable)
% Any variables declared here will be accessible to the callbacks
% Initialize output
outputVariable = [];
% Initialize newVariable
newVariable = [];
% Initialize main figure
hdl.mainfig = figure('CloseRequestFcn',#closefunction);
% Add Button
hdl.addPushButton = uicontrol(hdl.mainfig, 'Units', 'normalized', 'Position',[0.05 0.6 0.3 0.25], 'String', 'Add One', 'Callback', #addOne);
% Done Button
hdl.donePushButton = uicontrol(hdl.mainfig, 'Units', 'normalized', 'Position',[0.65 0.6 0.3 0.25], 'String', 'Done', 'Callback', #done);
% Static text
hdl.sliceNoText = uicontrol(hdl.mainfig,'Style','text','Fontsize',16,'Units','normalized','Position',[0.35 0.2 0.3 0.25]);
function addOne(hObject,eventdata)
inputVariable = inputVariable+1; % add one to the current inputVariable
set(hdl.sliceNoText, 'String', num2str(inputVariable)); % change static text
newVariable = inputVariable; % new variable to be exported
end
function closefunction(hObject,eventdata)
% This callback is executed if the user closes the gui
% Assign Output
outputVariable = newVariable;
% Close figure
delete(hdl.mainfig); % close GUI
end
function done(hObject,eventdata)
% Assign Output
outputVariable = newVariable;
% Close figure
delete(hdl.mainfig); % close GUI
end
% Pause until figure is closed ---------------------------------------%
waitfor(hdl.mainfig);
end