function varargout = convolutiondemo(varargin)
% CONVOLUTIONDEMO A graphical demonstration of 1-D convolution of two
% functions.
%
% Run the program for more details.
%
% 2009-09-23 v1.2   Removed a couple of unnecessary AXES commands,
%                   so it no longer crashes when dragging the
%                   slider around for a long time.
%
% 2009-09-03 v1.1   Now correctly replaces -Inf with 0
%                   Added time and value strings
%                   Adjusted slider step settings
%                   Now checks for installation of toolboxes
%                   Slightly clearer information dialog text
%                   Cleaned up some unnecessary variables
%                   Added Mathworks Copyright
%
% 2009-09-02 v1.0   Initial Creation
%
% Teja.Muppirala@mathworks.com
% Copyright 2009, The MathWorks, Inc. 

% Edit the above text to modify the response to help convolutiondemo

% Last Modified by GUIDE v2.5 01-Sep-2009 23:56:59

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @convolutiondemo_OpeningFcn, ...
                   'gui_OutputFcn',  @convolutiondemo_OutputFcn, ...
                   'gui_LayoutFcn',  @convolutiondemo_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
% End initialization code - DO NOT EDIT


% --- Executes just before convolutiondemo is made visible.
function convolutiondemo_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);

%% Set up transfer function variable and initialize
global s
if ~isempty(ver('control')) %toolbox check
    s = tf('s');
end
set(gcf,'userdata',0); % 0 means data is good. 1 means data is bad.
pushbutton2_Callback(hObject, eventdata, handles)
pushbutton1_Callback(hObject, eventdata, handles)

% --- Outputs from this function are returned to the command line.
function varargout = convolutiondemo_OutputFcn(~, eventdata, handles) 
varargout{1} = handles.output;


function slider1_Callback(hObject, eventdata, handles)
%% Executes on slider movement.
global t h_f f g h_prod tlloc h_line tzloc gf

if(get(gcf,'userdata')) % Just an extra check to make sure the data is good
    return
end

% Do all the updating
set(h_f,'Ydata',f((tlloc:end)-round(get(hObject,'Value'))));
set(h_prod,'Ydata', get(h_f,'Ydata') .*  g(tlloc:end));

set(handles.slider1,'userdata',get(handles.slider1,'value'));

set(h_line,'Xdata',[1 1]*[t(tzloc+round(get(hObject,'value')))]);

set(handles.text_timestring,'string',['t = ' ...
    num2str(t(tzloc+round(get(hObject,'value'))),3)]);

set(handles.text_convstring,'string',['value = ' ...
    num2str(gf(tzloc+round(get(hObject,'value'))),3)]);

% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
%% On mouse motion, call the slider callback if it has changed position
if get(handles.slider1,'value') ~= get(handles.slider1,'userdata') && ~get(gcf,'userdata')
    slider1_Callback(handles.slider1, eventdata, handles)
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function pushbutton1_Callback(hObject, eventdata, handles)
%% Start Recalculate button callback. (To line 211)
global t h_f f g h_prod tlloc tmax tmin dt h_line tzloc s gf

%% Read in values from the GUI
set(handles.axes1,'visible','off');
tmax = str2double(get(handles.edit4,'String'));
tmin = str2double(get(handles.edit3,'String'));
dt = 1 / str2double(get(handles.edit5,'String'));
t = -(tmax-tmin):dt:tmax-tmin; % The actual time vector is longer than just tmin:tmax
axes(handles.axes1);
cla;
set(gca,'SortMethod','childorder');
tlloc = find(t == tmin);
tzloc = find(t == 0);
inputisbad = 1;

try
%% Read G and F
    % First F
    try % Maybe it is a function of t
        f0 = [(t >= 0).* eval(vectorize(get(handles.edit1,'String')))];
        inputisbad = 0;
    catch
        try % Maybe it is a transfer function
            if ~isscalar(eval(get(handles.edit1,'String'))); error; end %Don't try to take the impulse of a big vector...
            f0 = eval(['impulse(' get(handles.edit1,'String') ', t(t >= 0));']);
            f0 = [0*t(t < 0) f0'];
            FD = eval(['freqresp(' get(handles.edit1,'String') ',Inf);']);
            if FD ~= 0
                warndlg('F(s) is not strictly proper. Direct feedthrough terms will be set to zero.');
                uiwait;
            end
            inputisbad = 0;
        catch  % Maybe it is a workspace expression
            f0 = evalin('base',get(handles.edit1,'String'));
            f0 = [0*t(t < 0) f0];
            if length(t) ~= length(f0)
                set(gcf,'userdata',1); % Flag for bad data
                errordlg(['The size of F must be 1 x ' num2str((tmax-tmin)/dt + 1)]);
                return;
            end
            inputisbad = 0;
        end
    end
    
    % Repeat for G
    try
        g = [eval(vectorize(get(handles.edit2,'String')))] .* (t >= 0); 
        inputisbad = 0;
    catch
        try
            if ~isscalar(eval(get(handles.edit2,'String'))); error; end %Don't try to take the impulse of a big vector...
            g = eval(['impulse(' get(handles.edit2,'String') ', t(t >= 0));']);
            g = [0*t(t < 0) g'];
            GD = eval(['freqresp(' get(handles.edit2,'String') ',Inf);']);
            if GD ~= 0
                warndlg('G(s) is not strictly proper. Direct feedthrough terms will be set to zero.');
                uiwait;
            end
            inputisbad = 0;
        catch
            g = evalin('base',get(handles.edit2,'String'));
            g = [0*t(t < 0) g 0*t(t > tmax)];
            if length(g) ~= length(f0)
                set(gcf,'userdata',1); % Flag for bad data
                errordlg(['The size of G must be 1 x ' num2str(tmax/dt + 1)]);
                return;
            end
            inputisbad = 0;
        end
    end
catch
%% Misunderstood input...
    errordlg('Could not parse input.');
    uiwait; return;
end

%% Set up the data and plot on Axis 1
% Give the slider a new max and step based on the new data
set(handles.slider1,'userdata',get(handles.slider1,'value'));
set(handles.slider1,'max',(tlloc-1));
set(handles.slider1,'sliderstep',[1/(tlloc-1) 100/(tlloc-1)]);

% Don't let the slider go past its maximum
if get(handles.slider1,'value') > (tlloc-1)
    set(handles.slider1,'value',tlloc-1)
end

% Get rid of bad points...
f0(isinf(f0)) = 0; f0(isnan(f0)) = 0;
g(isinf(g)) = 0; g(isnan(g)) = 0;

f = fliplr(f0); 

convloc = find(t >= 0 & t <= tmax); %Only take the needed part of the convolution

h_f = plot(t(tlloc:end),f(tlloc:end),'Visible','off'); hold on; % Handle for F
h_g = plot(t,g,'r'); %Handle for G
h_prod = area(t(tlloc:end),0*f(tlloc:end),'facecolor',[.5 .5 .5]); %Handle the gray area
set(gca,'Children',[h_g;h_f; h_prod]); % Arrangle the order of the plots 

% Set the axis limits to fit all the data
maxmins = [-max(abs([g f g.*f])) max(abs([g f g.*f]))];
if isequal(maxmins,[0 0]), maxmins = [-1 1]; end

% Calculate the convolution
gf = conv(g(convloc),f0(convloc)) * dt; gf = gf(1:length(convloc));
gf = [zeros(1,length(t(t < 0))) gf];

% Apply limits
xlim([tmin tmax]); ylim(maxmins);

%% Switch over to axis 2 and draw f * g
axes(handles.axes2);
cla
set(gca,'SortMethod','childorder');
h_conv = plot([t(t<0) t(convloc)],gf,'k');
xlim([tmin tmax]); 
grid on; hold on;
h_line = plot([0 0],[ylim],'k:');

%% Execute the slider callback once with the new data
slider1_Callback(handles.slider1, eventdata, handles);

set(handles.axes1,'visible','on');
set(h_f,'visible','on');
set(gcf,'userdata',0); %Just saying that everything worked ok.

%%% END OF RECALCULATE BUTTON CALLBACK (From line 85)


function pushbutton2_Callback(~, eventdata, handles)
%% Info Button Callback.
usetext = {'Convolution Demo: '
            ''
            'Any causal LTI transfer function operator F(s) can be expressed'
            'as a convolution integral in the time domain, where the convolution'
            'kernel f(t) = 0 for t < 0. While the textbook definition of the'
            'convolution of two functions is quite straightforward, it may be a'
            'little difficult to grasp geometrically at first.'
            ''
            'This program takes inputs f and g, and using the slider displays'
            'their convolution as the signed area of the gray region defined by'
            'f(t-tau) multiplied by g(t).'
            ''
            'F and G may be input as: '
            ''
            ' 1. Time domain functions of t'
            '    Examples: "exp(-t)" or "t^2" or "sin(5*t-1)"'
            ''
            ' 2. Transfer functions (needs Control System Toolbox).'
            '    "Examples: 1/s" or "10/(s^2+100)" or "exp(-s)/(s-1)"'
            '    Delays are OK, but direct feedthrough terms are not. They lead'
            '    to impulses in the time domain, and are not supported.'
            ''
            ' 3. An expression to be evaluated in the base workspace. '
            '    Example: "myvariable" or "randn(1,2801)"'
            '    The size of f must be given as [1  x  (tmax-tmin)/dt+1]'
            '    The size of g must be given as [1  x  tmax/dt+1]'
            '    where tmax, tmin, and dt are as specified in the'
            '    "Time display limits:" boxes in the GUI.'};
        
h = msgbox(usetext); set(h,'name','Convolution Demo - Help')    
uiwait(h);

%% %%%% EVERYTHING BELOW IS JUST ADMINISTRATIVE STUFF %%%%%%%%

%% Unused Callbacks List
function edit1_Callback(~, ~, handles)

function edit1_CreateFcn(hObject, eventdata, handles)
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white');
    end

function edit2_Callback(hObject, eventdata, handles)

function edit2_CreateFcn(hObject, eventdata, handles)
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white');
    end

function edit3_Callback(hObject, eventdata, handles)
    
function edit3_CreateFcn(hObject, eventdata, handles)
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white');
    end

function edit4_Callback(hObject, eventdata, handles)

function figure1_WindowButtonUpFcn(hObject, eventdata, handles)
function figure1_WindowButtonDownFcn(hObject, eventdata, handles)

function edit4_CreateFcn(hObject, eventdata, handles)
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white');
    end

function edit5_Callback(hObject, eventdata, handles)

function edit5_CreateFcn(hObject, eventdata, handles)
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white');
    end

%%%%%%%%%%%%%%%%%%%%%%% GUIDE created stuff is below %%%%%%%%%%%%%%%%%%%%%%

% --- Creates and returns a handle to the GUI figure. 
function h1 = convolutiondemo_LayoutFcn(policy)
% policy - create a new figure or use a singleton. 'new' or 'reuse'.

persistent hsingleton;
if strcmpi(policy, 'reuse') & ishandle(hsingleton)
    h1 = hsingleton;
    return;
end

appdata = [];
appdata.GUIDEOptions = struct(...
    'active_h', 194.005981445313, ...
    'taginfo', struct(...
    'figure', 2, ...
    'axes', 3, ...
    'slider', 2, ...
    'edit', 6, ...
    'pushbutton', 3, ...
    'text', 6), ...
    'override', 1, ...
    'release', 13, ...
    'resize', 'simple', ...
    'accessibility', 'callback', ...
    'mfile', 1, ...
    'callbacks', 1, ...
    'singleton', 1, ...
    'syscolorfig', 1, ...
    'blocking', 0 ...
    );
appdata.lastValidTag = 'figure1';
appdata.GUIDELayoutEditor = [];
appdata.initTags = struct(...
    'handle', [], ...
    'tag', 'figure1');

h1 = figure(...
'Units','characters',...
'PaperUnits',get(0,'defaultfigurePaperUnits'),...
'Color',[0.831372549019608 0.815686274509804 0.784313725490196],...
'Colormap',[0 0 0.5625;0 0 0.625;0 0 0.6875;0 0 0.75;0 0 0.8125;0 0 0.875;0 0 0.9375;0 0 1;0 0.0625 1;0 0.125 1;0 0.1875 1;0 0.25 1;0 0.3125 1;0 0.375 1;0 0.4375 1;0 0.5 1;0 0.5625 1;0 0.625 1;0 0.6875 1;0 0.75 1;0 0.8125 1;0 0.875 1;0 0.9375 1;0 1 1;0.0625 1 1;0.125 1 0.9375;0.1875 1 0.875;0.25 1 0.8125;0.3125 1 0.75;0.375 1 0.6875;0.4375 1 0.625;0.5 1 0.5625;0.5625 1 0.5;0.625 1 0.4375;0.6875 1 0.375;0.75 1 0.3125;0.8125 1 0.25;0.875 1 0.1875;0.9375 1 0.125;1 1 0.0625;1 1 0;1 0.9375 0;1 0.875 0;1 0.8125 0;1 0.75 0;1 0.6875 0;1 0.625 0;1 0.5625 0;1 0.5 0;1 0.4375 0;1 0.375 0;1 0.3125 0;1 0.25 0;1 0.1875 0;1 0.125 0;1 0.0625 0;1 0 0;0.9375 0 0;0.875 0 0;0.8125 0 0;0.75 0 0;0.6875 0 0;0.625 0 0;0.5625 0 0],...
'IntegerHandle','off',...
'InvertHardcopy',get(0,'defaultfigureInvertHardcopy'),...
'MenuBar','none',...
'Name','Convolution Demo v1.2',...
'NumberTitle','off',...
'PaperPosition',get(0,'defaultfigurePaperPosition'),...
'PaperSize',[20.98404194812 29.67743169791],...
'PaperType',get(0,'defaultfigurePaperType'),...
'Position',[103.833333333333 2 133.666666666667 59.5],...
'WindowButtonDownFcn',@(hObject,eventdata)convolutiondemo('figure1_WindowButtonDownFcn',hObject,eventdata,guidata(hObject)),...
'WindowButtonMotionFcn',@(hObject,eventdata)convolutiondemo('figure1_WindowButtonMotionFcn',hObject,eventdata,guidata(hObject)),...
'WindowButtonUpFcn',@(hObject,eventdata)convolutiondemo('figure1_WindowButtonUpFcn',hObject,eventdata,guidata(hObject)),...
'HandleVisibility','callback',...
'Tag','figure1',...
'UserData',[],...
'Visible','on',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

appdata = [];
appdata.lastValidTag = 'axes1';

h2 = axes(...
'Parent',h1,...
'Position',[0.0572139303482587 0.582466567607727 0.738805970149254 0.387815750371471],...
'CameraPosition',[0.5 0.5 9.16025403784439],...
'CameraPositionMode',get(0,'defaultaxesCameraPositionMode'),...
'Color',get(0,'defaultaxesColor'),...
'ColorOrder',get(0,'defaultaxesColorOrder'),...
'FontName',get(0,'defaultaxesFontName'),...
'FontSize',get(0,'defaultaxesFontSize'),...
'LooseInset',[0.168497023809524 0.225309763689431 0.12313244047619 0.153620293424612],...
'XColor',get(0,'defaultaxesXColor'),...
'YColor',get(0,'defaultaxesYColor'),...
'ZColor',get(0,'defaultaxesZColor'),...
'Tag','axes1',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

appdata = [];
appdata.SerializedAnnotationV7 = struct(...
    'LegendInformation', struct(...
    'IconDisplayStyle', 'on'));

h3 = get(h2,'title');

set(h3,...
'Parent',h2,...
'Units','data',...
'FontUnits','points',...
'BackgroundColor','none',...
'Color',[0 0 0],...
'DisplayName',blanks(0),...
'EdgeColor','none',...
'EraseMode','normal',...
'DVIMode','auto',...
'FontAngle','normal',...
'FontName','MS UI Gothic',...
'FontSize',9,...
'FontWeight','normal',...
'HorizontalAlignment','center',...
'LineStyle','-',...
'LineWidth',0.5,...
'Margin',2,...
'Position',[0.499155405405405 1.01624548736462 1.00005459937205],...
'Rotation',0,...
'String',blanks(0),...
'Interpreter','tex',...
'VerticalAlignment','bottom',...
'ButtonDownFcn',[],...
'CreateFcn', {@local_CreateFcn, [], appdata} ,...
'DeleteFcn',[],...
'BusyAction','queue',...
'HandleVisibility','off',...
'HelpTopicKey',blanks(0),...
'HitTest','on',...
'Interruptible','on',...
'SelectionHighlight','on',...
'Serializable','on',...
'Tag',blanks(0),...
'UserData',[],...
'Visible','on',...
'XLimInclude','on',...
'YLimInclude','on',...
'ZLimInclude','on',...
'CLimInclude','on',...
'ALimInclude','on',...
'IncludeRenderer','on',...
'Clipping','off');

appdata = [];
appdata.SerializedAnnotationV7 = struct(...
    'LegendInformation', struct(...
    'IconDisplayStyle', 'on'));

h4 = get(h2,'xlabel');

set(h4,...
'Parent',h2,...
'Units','data',...
'FontUnits','points',...
'BackgroundColor','none',...
'Color',[0 0 0],...
'DisplayName',blanks(0),...
'EdgeColor','none',...
'EraseMode','normal',...
'DVIMode','auto',...
'FontAngle','normal',...
'FontName','MS UI Gothic',...
'FontSize',9,...
'FontWeight','normal',...
'HorizontalAlignment','center',...
'LineStyle','-',...
'LineWidth',0.5,...
'Margin',2,...
'Position',[0.499155405405405 -0.0740072202166067 1.00005459937205],...
'Rotation',0,...
'String',blanks(0),...
'Interpreter','tex',...
'VerticalAlignment','cap',...
'ButtonDownFcn',[],...
'CreateFcn', {@local_CreateFcn, [], appdata} ,...
'DeleteFcn',[],...
'BusyAction','queue',...
'HandleVisibility','off',...
'HelpTopicKey',blanks(0),...
'HitTest','on',...
'Interruptible','on',...
'SelectionHighlight','on',...
'Serializable','on',...
'Tag',blanks(0),...
'UserData',[],...
'Visible','on',...
'XLimInclude','on',...
'YLimInclude','on',...
'ZLimInclude','on',...
'CLimInclude','on',...
'ALimInclude','on',...
'IncludeRenderer','on',...
'Clipping','off');

appdata = [];
appdata.SerializedAnnotationV7 = struct(...
    'LegendInformation', struct(...
    'IconDisplayStyle', 'on'));

h5 = get(h2,'ylabel');

set(h5,...
'Parent',h2,...
'Units','data',...
'FontUnits','points',...
'BackgroundColor','none',...
'Color',[0 0 0],...
'DisplayName',blanks(0),...
'EdgeColor','none',...
'EraseMode','normal',...
'DVIMode','auto',...
'FontAngle','normal',...
'FontName','MS UI Gothic',...
'FontSize',9,...
'FontWeight','normal',...
'HorizontalAlignment','center',...
'LineStyle','-',...
'LineWidth',0.5,...
'Margin',2,...
'Position',[-0.0413851351351351 0.496389891696751 1.00005459937205],...
'Rotation',90,...
'String',blanks(0),...
'Interpreter','tex',...
'VerticalAlignment','bottom',...
'ButtonDownFcn',[],...
'CreateFcn', {@local_CreateFcn, [], appdata} ,...
'DeleteFcn',[],...
'BusyAction','queue',...
'HandleVisibility','off',...
'HelpTopicKey',blanks(0),...
'HitTest','on',...
'Interruptible','on',...
'SelectionHighlight','on',...
'Serializable','on',...
'Tag',blanks(0),...
'UserData',[],...
'Visible','on',...
'XLimInclude','on',...
'YLimInclude','on',...
'ZLimInclude','on',...
'CLimInclude','on',...
'ALimInclude','on',...
'IncludeRenderer','on',...
'Clipping','off');

appdata = [];
appdata.SerializedAnnotationV7 = struct(...
    'LegendInformation', struct(...
    'IconDisplayStyle', 'on'));

h6 = get(h2,'zlabel');

set(h6,...
'Parent',h2,...
'Units','data',...
'FontUnits','points',...
'BackgroundColor','none',...
'Color',[0 0 0],...
'DisplayName',blanks(0),...
'EdgeColor','none',...
'EraseMode','normal',...
'DVIMode','auto',...
'FontAngle','normal',...
'FontName','MS UI Gothic',...
'FontSize',9,...
'FontWeight','normal',...
'HorizontalAlignment','right',...
'LineStyle','-',...
'LineWidth',0.5,...
'Margin',2,...
'Position',[-0.0785472972972973 1.07039711191336 1.00005459937205],...
'Rotation',0,...
'String',blanks(0),...
'Interpreter','tex',...
'VerticalAlignment','middle',...
'ButtonDownFcn',[],...
'CreateFcn', {@local_CreateFcn, [], appdata} ,...
'DeleteFcn',[],...
'BusyAction','queue',...
'HandleVisibility','off',...
'HelpTopicKey',blanks(0),...
'HitTest','on',...
'Interruptible','on',...
'SelectionHighlight','on',...
'Serializable','on',...
'Tag',blanks(0),...
'UserData',[],...
'Visible','off',...
'XLimInclude','on',...
'YLimInclude','on',...
'ZLimInclude','on',...
'CLimInclude','on',...
'ALimInclude','on',...
'IncludeRenderer','on',...
'Clipping','off');

appdata = [];
appdata.lastValidTag = 'axes2';

h7 = axes(...
'Parent',h1,...
'Position',[0.0559701492537313 0.0445765230312035 0.740049751243781 0.387815750371471],...
'CameraPosition',[0.5 0.5 9.16025403784439],...
'CameraPositionMode',get(0,'defaultaxesCameraPositionMode'),...
'Color',get(0,'defaultaxesColor'),...
'ColorOrder',get(0,'defaultaxesColorOrder'),...
'FontName',get(0,'defaultaxesFontName'),...
'FontSize',get(0,'defaultaxesFontSize'),...
'LooseInset',[0.168417071853052 0.225309763689431 0.123074014046461 0.153620293424612],...
'XColor',get(0,'defaultaxesXColor'),...
'YColor',get(0,'defaultaxesYColor'),...
'ZColor',get(0,'defaultaxesZColor'),...
'Tag','axes2',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

appdata = [];
appdata.SerializedAnnotationV7 = struct(...
    'LegendInformation', struct(...
    'IconDisplayStyle', 'on'));

h8 = get(h7,'title');

set(h8,...
'Parent',h7,...
'Units','data',...
'FontUnits','points',...
'BackgroundColor','none',...
'Color',[0 0 0],...
'DisplayName',blanks(0),...
'EdgeColor','none',...
'EraseMode','normal',...
'DVIMode','auto',...
'FontAngle','normal',...
'FontName','MS UI Gothic',...
'FontSize',9,...
'FontWeight','normal',...
'HorizontalAlignment','center',...
'LineStyle','-',...
'LineWidth',0.5,...
'Margin',2,...
'Position',[0.5 1.01624548736462 1.00005459937205],...
'Rotation',0,...
'String',blanks(0),...
'Interpreter','tex',...
'VerticalAlignment','bottom',...
'ButtonDownFcn',[],...
'CreateFcn', {@local_CreateFcn, [], appdata} ,...
'DeleteFcn',[],...
'BusyAction','queue',...
'HandleVisibility','off',...
'HelpTopicKey',blanks(0),...
'HitTest','on',...
'Interruptible','on',...
'SelectionHighlight','on',...
'Serializable','on',...
'Tag',blanks(0),...
'UserData',[],...
'Visible','on',...
'XLimInclude','on',...
'YLimInclude','on',...
'ZLimInclude','on',...
'CLimInclude','on',...
'ALimInclude','on',...
'IncludeRenderer','on',...
'Clipping','off');

appdata = [];
appdata.SerializedAnnotationV7 = struct(...
    'LegendInformation', struct(...
    'IconDisplayStyle', 'on'));

h9 = get(h7,'xlabel');

set(h9,...
'Parent',h7,...
'Units','data',...
'FontUnits','points',...
'BackgroundColor','none',...
'Color',[0 0 0],...
'DisplayName',blanks(0),...
'EdgeColor','none',...
'EraseMode','normal',...
'DVIMode','auto',...
'FontAngle','normal',...
'FontName','MS UI Gothic',...
'FontSize',9,...
'FontWeight','normal',...
'HorizontalAlignment','center',...
'LineStyle','-',...
'LineWidth',0.5,...
'Margin',2,...
'Position',[0.498313659359191 -0.0740072202166067 1.00005459937205],...
'Rotation',0,...
'String',blanks(0),...
'Interpreter','tex',...
'VerticalAlignment','cap',...
'ButtonDownFcn',[],...
'CreateFcn', {@local_CreateFcn, [], appdata} ,...
'DeleteFcn',[],...
'BusyAction','queue',...
'HandleVisibility','off',...
'HelpTopicKey',blanks(0),...
'HitTest','on',...
'Interruptible','on',...
'SelectionHighlight','on',...
'Serializable','on',...
'Tag',blanks(0),...
'UserData',[],...
'Visible','on',...
'XLimInclude','on',...
'YLimInclude','on',...
'ZLimInclude','on',...
'CLimInclude','on',...
'ALimInclude','on',...
'IncludeRenderer','on',...
'Clipping','off');

appdata = [];
appdata.SerializedAnnotationV7 = struct(...
    'LegendInformation', struct(...
    'IconDisplayStyle', 'on'));

h10 = get(h7,'ylabel');

set(h10,...
'Parent',h7,...
'Units','data',...
'FontUnits','points',...
'BackgroundColor','none',...
'Color',[0 0 0],...
'DisplayName',blanks(0),...
'EdgeColor','none',...
'EraseMode','normal',...
'DVIMode','auto',...
'FontAngle','normal',...
'FontName','MS UI Gothic',...
'FontSize',9,...
'FontWeight','normal',...
'HorizontalAlignment','center',...
'LineStyle','-',...
'LineWidth',0.5,...
'Margin',2,...
'Position',[-0.0413153456998314 0.496389891696751 1.00005459937205],...
'Rotation',90,...
'String',blanks(0),...
'Interpreter','tex',...
'VerticalAlignment','bottom',...
'ButtonDownFcn',[],...
'CreateFcn', {@local_CreateFcn, [], appdata} ,...
'DeleteFcn',[],...
'BusyAction','queue',...
'HandleVisibility','off',...
'HelpTopicKey',blanks(0),...
'HitTest','on',...
'Interruptible','on',...
'SelectionHighlight','on',...
'Serializable','on',...
'Tag',blanks(0),...
'UserData',[],...
'Visible','on',...
'XLimInclude','on',...
'YLimInclude','on',...
'ZLimInclude','on',...
'CLimInclude','on',...
'ALimInclude','on',...
'IncludeRenderer','on',...
'Clipping','off');

appdata = [];
appdata.SerializedAnnotationV7 = struct(...
    'LegendInformation', struct(...
    'IconDisplayStyle', 'on'));

h11 = get(h7,'zlabel');

set(h11,...
'Parent',h7,...
'Units','data',...
'FontUnits','points',...
'BackgroundColor','none',...
'Color',[0 0 0],...
'DisplayName',blanks(0),...
'EdgeColor','none',...
'EraseMode','normal',...
'DVIMode','auto',...
'FontAngle','normal',...
'FontName','MS UI Gothic',...
'FontSize',9,...
'FontWeight','normal',...
'HorizontalAlignment','right',...
'LineStyle','-',...
'LineWidth',0.5,...
'Margin',2,...
'Position',[-0.0767284991568297 2.45667870036101 1.00005459937205],...
'Rotation',0,...
'String',blanks(0),...
'Interpreter','tex',...
'VerticalAlignment','middle',...
'ButtonDownFcn',[],...
'CreateFcn', {@local_CreateFcn, [], appdata} ,...
'DeleteFcn',[],...
'BusyAction','queue',...
'HandleVisibility','off',...
'HelpTopicKey',blanks(0),...
'HitTest','on',...
'Interruptible','on',...
'SelectionHighlight','on',...
'Serializable','on',...
'Tag',blanks(0),...
'UserData',[],...
'Visible','off',...
'XLimInclude','on',...
'YLimInclude','on',...
'ZLimInclude','on',...
'CLimInclude','on',...
'ALimInclude','on',...
'IncludeRenderer','on',...
'Clipping','off');

appdata = [];
appdata.lastValidTag = 'slider1';

h12 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'BackgroundColor',[0.9 0.9 0.9],...
'Callback',@(hObject,eventdata)convolutiondemo('slider1_Callback',hObject,eventdata,guidata(hObject)),...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',get(0,'defaultuicontrolFontSize'),...
'Position',[0.0572139303482587 0.521545319465082 0.738805970149254 0.0312035661218425],...
'String',{  'ƒXƒ‰ƒCƒ_' },...
'Style','slider',...
'SliderStep',[0.001 0.1],...
'CreateFcn', {@local_CreateFcn, @(hObject,eventdata)convolutiondemo('slider1_CreateFcn',hObject,eventdata,guidata(hObject)), appdata} ,...
'Tag','slider1');

appdata = [];
appdata.lastValidTag = 'edit1';

h13 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)convolutiondemo('edit1_Callback',hObject,eventdata,guidata(hObject)),...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',get(0,'defaultuicontrolFontSize'),...
'Position',[0.820448877805486 0.897759103641457 0.150872817955112 0.030812324929972],...
'String','exp(-1*t)',...
'Style','edit',...
'CreateFcn', {@local_CreateFcn, @(hObject,eventdata)convolutiondemo('edit1_CreateFcn',hObject,eventdata,guidata(hObject)), appdata} ,...
'Tag','edit1');



appdata = [];
appdata.lastValidTag = 'edit2';

h14 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)convolutiondemo('edit2_Callback',hObject,eventdata,guidata(hObject)),...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',get(0,'defaultuicontrolFontSize'),...
'Position',[0.819201995012469 0.80812324929972 0.150872817955112 0.030812324929972],...
'String','sin(2*pi*t)',...
'Style','edit',...
'CreateFcn', {@local_CreateFcn, @(hObject,eventdata)convolutiondemo('edit2_CreateFcn',hObject,eventdata,guidata(hObject)), appdata} ,...
'Tag','edit2');

appdata = [];
appdata.lastValidTag = 'edit3';

h15 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)convolutiondemo('edit3_Callback',hObject,eventdata,guidata(hObject)),...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',get(0,'defaultuicontrolFontSize'),...
'Position',[0.820448877805486 0.749299719887955 0.0698254364089776 0.030812324929972],...
'String','-2',...
'Style','edit',...
'CreateFcn', {@local_CreateFcn, @(hObject,eventdata)convolutiondemo('edit3_CreateFcn',hObject,eventdata,guidata(hObject)), appdata} ,...
'Tag','edit3');

appdata = [];
appdata.lastValidTag = 'edit4';

h16 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)convolutiondemo('edit4_Callback',hObject,eventdata,guidata(hObject)),...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',get(0,'defaultuicontrolFontSize'),...
'Position',[0.900249376558603 0.749299719887955 0.0698254364089776 0.030812324929972],...
'String','5',...
'Style','edit',...
'CreateFcn', {@local_CreateFcn, @(hObject,eventdata)convolutiondemo('edit4_CreateFcn',hObject,eventdata,guidata(hObject)), appdata} ,...
'Tag','edit4');

appdata = [];
appdata.lastValidTag = 'edit5';

h17 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)convolutiondemo('edit5_Callback',hObject,eventdata,guidata(hObject)),...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',get(0,'defaultuicontrolFontSize'),...
'Position',[0.820448877805486 0.689075630252101 0.150872817955112 0.030812324929972],...
'String','400',...
'Style','edit',...
'CreateFcn', {@local_CreateFcn, @(hObject,eventdata)convolutiondemo('edit5_CreateFcn',hObject,eventdata,guidata(hObject)), appdata} ,...
'Tag','edit5');

appdata = [];
appdata.lastValidTag = 'pushbutton1';

h18 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'Callback',@(hObject,eventdata)convolutiondemo('pushbutton1_Callback',hObject,eventdata,guidata(hObject)),...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',get(0,'defaultuicontrolFontSize'),...
'Position',[0.820448877805486 0.605042016806723 0.150872817955112 0.0546218487394958],...
'String','Recalculate',...
'Tag','pushbutton1',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

appdata = [];
appdata.lastValidTag = 'text1';

h19 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',get(0,'defaultuicontrolFontSize'),...
'ForegroundColor',[0 0 1],...
'HorizontalAlignment','left',...
'Position',[0.819201995012469 0.927170868347339 0.175810473815461 0.0434173669467787],...
'String','f(t) or strictly proper F(s) or workspace expression:',...
'Style','text',...
'Tag','text1',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

h20 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',get(0,'defaultuicontrolFontSize'),...
'ForegroundColor',[1 0 0],...
'HorizontalAlignment','left',...
'Position',[0.819201995012469 0.837535014005602 0.175810473815461 0.0434173669467787],...
'String','g(t) or strictly proper G(s) or workspace expression:',...
'Style','text',...
'Tag','text2',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

h_timestring = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',12,...
'ForegroundColor',[0 0 0],...
'HorizontalAlignment','left',...
'Position',[0.819201995012469 0.25 0.175810473815461 0.0434173669467787],...
'String','t = 0',...
'Style','text',...
'Tag','text_timestring',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

appdata = [];
appdata.lastValidTag = 'text2';

h_convstring = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',12,...
'ForegroundColor',[0 0 0],...
'HorizontalAlignment','left',...
'Position',[0.819201995012469 0.15 0.175810473815461 0.1134173669467787],...
'String','value = 0 ',...
'Style','text',...
'Tag','text_convstring',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

appdata = [];
appdata.lastValidTag = 'text3';

h21 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',get(0,'defaultuicontrolFontSize'),...
'HorizontalAlignment','left',...
'Position',[0.819201995012469 0.778711484593838 0.175810473815461 0.0196078431372549],...
'String','Time display limits:',...
'Style','text',...
'Tag','text3',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

appdata = [];
appdata.lastValidTag = 'text4';

h22 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',get(0,'defaultuicontrolFontSize'),...
'HorizontalAlignment','left',...
'Position',[0.820448877805486 0.718487394957983 0.175810473815461 0.0196078431372549],...
'String','t sample rate (= 1/dt)',...
'Style','text',...
'Tag','text4',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

appdata = [];
appdata.lastValidTag = 'text5';

h23 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'FontName','Times New Roman',...
'FontSize',16,...
'Position',[0.247512437810945 0.432392273402675 0.349502487562189 0.0475482912332838],...
'String','f * g',...
'Style','text',...
'Tag','text5',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

appdata = [];
appdata.lastValidTag = 'pushbutton2';

h24 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'Callback',@(hObject,eventdata)convolutiondemo('pushbutton2_Callback',hObject,eventdata,guidata(hObject)),...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',get(0,'defaultuicontrolFontSize'),...
'Position',[0.820448877805486 0.521008403361345 0.150872817955112 0.0574229691876751],...
'String','Info/Help',...
'Tag','pushbutton2',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );


hsingleton = h1;


% --- Set application data first then calling the CreateFcn. 
function local_CreateFcn(hObject, eventdata, createfcn, appdata)

if ~isempty(appdata)
   names = fieldnames(appdata);
   for i=1:length(names)
       name = char(names(i));
       setappdata(hObject, name, getfield(appdata,name));
   end
end

if ~isempty(createfcn)
   if isa(createfcn,'function_handle')
       createfcn(hObject, eventdata);
   else
       eval(createfcn);
   end
end


% --- Handles default GUIDE GUI creation and callback dispatch
function varargout = gui_mainfcn(gui_State, varargin)

gui_StateFields =  {'gui_Name'
    'gui_Singleton'
    'gui_OpeningFcn'
    'gui_OutputFcn'
    'gui_LayoutFcn'
    'gui_Callback'};
gui_Mfile = '';
for i=1:length(gui_StateFields)
    if ~isfield(gui_State, gui_StateFields{i})
        error('MATLAB:gui_mainfcn:FieldNotFound', 'Could not find field %s in the gui_State struct in GUI M-file %s', gui_StateFields{i}, gui_Mfile);
    elseif isequal(gui_StateFields{i}, 'gui_Name')
        gui_Mfile = [gui_State.(gui_StateFields{i}), '.m'];
    end
end

numargin = length(varargin);

if numargin == 0
    % CONVOLUTIONDEMO
    % create the GUI only if we are not in the process of loading it
    % already
    gui_Create = true;
elseif local_isInvokeActiveXCallback(gui_State, varargin{:})
    % CONVOLUTIONDEMO(ACTIVEX,...)
    vin{1} = gui_State.gui_Name;
    vin{2} = [get(varargin{1}.Peer, 'Tag'), '_', varargin{end}];
    vin{3} = varargin{1};
    vin{4} = varargin{end-1};
    vin{5} = guidata(varargin{1}.Peer);
    feval(vin{:});
    return;
elseif local_isInvokeHGCallbak(gui_State, varargin{:})
    % CONVOLUTIONDEMO('CALLBACK',hObject,eventData,handles,...)
    gui_Create = false;
else
    % CONVOLUTIONDEMO(...)
    % create the GUI and hand varargin to the openingfcn
    gui_Create = true;
end

if ~gui_Create
    % In design time, we need to mark all components possibly created in
    % the coming callback evaluation as non-serializable. This way, they
    % will not be brought into GUIDE and not be saved in the figure file
    % when running/saving the GUI from GUIDE.
    designEval = false;
    if (numargin>1 && ishghandle(varargin{2}))
        fig = varargin{2};
        while ~isempty(fig) && ~isgraphics(fig,'figure')
            fig = get(fig,'parent');
        end
        
        designEval = isappdata(0,'CreatingGUIDEFigure') || isprop(fig,'__GUIDEFigure');
    end
        
    if designEval
        beforeChildren = findall(fig);
    end
    
    % evaluate the callback now
    varargin{1} = gui_State.gui_Callback;
    if nargout
        [varargout{1:nargout}] = feval(varargin{:});
    else       
        feval(varargin{:});
    end
    
    % Set serializable of objects created in the above callback to off in
    % design time. Need to check whether figure handle is still valid in
    % case the figure is deleted during the callback dispatching.
    if designEval && ishandle(fig)
        set(setdiff(findall(fig),beforeChildren), 'Serializable','off');
    end
else
    if gui_State.gui_Singleton
        gui_SingletonOpt = 'reuse';
    else
        gui_SingletonOpt = 'new';
    end

    % Check user passing 'visible' P/V pair first so that its value can be
    % used by oepnfig to prevent flickering
    gui_Visible = 'auto';
    gui_VisibleInput = '';
    for index=1:2:length(varargin)
        if length(varargin) == index || ~ischar(varargin{index})
            break;
        end

        % Recognize 'visible' P/V pair
        len1 = min(length('visible'),length(varargin{index}));
        len2 = min(length('off'),length(varargin{index+1}));
        if ischar(varargin{index+1}) && strncmpi(varargin{index},'visible',len1) && len2 > 1
            if strncmpi(varargin{index+1},'off',len2)
                gui_Visible = 'invisible';
                gui_VisibleInput = 'off';
            elseif strncmpi(varargin{index+1},'on',len2)
                gui_Visible = 'visible';
                gui_VisibleInput = 'on';
            end
        end
    end
    
    % Open fig file with stored settings.  Note: This executes all component
    % specific CreateFunctions with an empty HANDLES structure.

    
    % Do feval on layout code in m-file if it exists
    gui_Exported = ~isempty(gui_State.gui_LayoutFcn);
    % this application data is used to indicate the running mode of a GUIDE
    % GUI to distinguish it from the design mode of the GUI in GUIDE. it is
    % only used by actxproxy at this time.   
    setappdata(0,genvarname(['OpenGuiWhenRunning_', gui_State.gui_Name]),1);
    if gui_Exported
        gui_hFigure = feval(gui_State.gui_LayoutFcn, gui_SingletonOpt);

        % make figure invisible here so that the visibility of figure is
        % consistent in OpeningFcn in the exported GUI case
        if isempty(gui_VisibleInput)
            gui_VisibleInput = get(gui_hFigure,'Visible');
        end
        set(gui_hFigure,'Visible','off')

        % openfig (called by local_openfig below) does this for guis without
        % the LayoutFcn. Be sure to do it here so guis show up on screen.
        movegui(gui_hFigure,'onscreen');
    else
        gui_hFigure = local_openfig(gui_State.gui_Name, gui_SingletonOpt, gui_Visible);
        % If the figure has InGUIInitialization it was not completely created
        % on the last pass.  Delete this handle and try again.
        if isappdata(gui_hFigure, 'InGUIInitialization')
            delete(gui_hFigure);
            gui_hFigure = local_openfig(gui_State.gui_Name, gui_SingletonOpt, gui_Visible);
        end
    end
    if isappdata(0, genvarname(['OpenGuiWhenRunning_', gui_State.gui_Name]))
        rmappdata(0,genvarname(['OpenGuiWhenRunning_', gui_State.gui_Name]));
    end

    % Set flag to indicate starting GUI initialization
    setappdata(gui_hFigure,'InGUIInitialization',1);

    % Fetch GUIDE Application options
    gui_Options = getappdata(gui_hFigure,'GUIDEOptions');
    % Singleton setting in the GUI M-file takes priority if different
    gui_Options.singleton = gui_State.gui_Singleton;

    if ~isappdata(gui_hFigure,'GUIOnScreen')
        % Adjust background color
        if gui_Options.syscolorfig
            set(gui_hFigure,'Color', get(0,'DefaultUicontrolBackgroundColor'));
        end

        % Generate HANDLES structure and store with GUIDATA. If there is
        % user set GUI data already, keep that also.
        data = guidata(gui_hFigure);
        handles = guihandles(gui_hFigure);
        if ~isempty(handles)
            if isempty(data)
                data = handles;
            else
                names = fieldnames(handles);
                for k=1:length(names)
                    data.(char(names(k)))=handles.(char(names(k)));
                end
            end
        end
        guidata(gui_hFigure, data);
    end

    % Apply input P/V pairs other than 'visible'
    for index=1:2:length(varargin)
        if length(varargin) == index || ~ischar(varargin{index})
            break;
        end

        len1 = min(length('visible'),length(varargin{index}));
        if ~strncmpi(varargin{index},'visible',len1)
            try set(gui_hFigure, varargin{index}, varargin{index+1}), catch break, end
        end
    end

    % If handle visibility is set to 'callback', turn it on until finished
    % with OpeningFcn
    gui_HandleVisibility = get(gui_hFigure,'HandleVisibility');
    if strcmp(gui_HandleVisibility, 'callback')
        set(gui_hFigure,'HandleVisibility', 'on');
    end

    feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});

    if isscalar(gui_hFigure) && ishandle(gui_hFigure)
        % Handle the default callbacks of predefined toolbar tools in this
        % GUI, if any
        guidemfile('restoreToolbarToolPredefinedCallback',gui_hFigure); 
        
        % Update handle visibility
        set(gui_hFigure,'HandleVisibility', gui_HandleVisibility);

        % Call openfig again to pick up the saved visibility or apply the
        % one passed in from the P/V pairs
        if ~gui_Exported
            gui_hFigure = local_openfig(gui_State.gui_Name, 'reuse',gui_Visible);
        elseif ~isempty(gui_VisibleInput)
            set(gui_hFigure,'Visible',gui_VisibleInput);
        end
        if strcmpi(get(gui_hFigure, 'Visible'), 'on')
            figure(gui_hFigure);
            
            if gui_Options.singleton
                setappdata(gui_hFigure,'GUIOnScreen', 1);
            end
        end

        % Done with GUI initialization
        if isappdata(gui_hFigure,'InGUIInitialization')
            rmappdata(gui_hFigure,'InGUIInitialization');
        end

        % If handle visibility is set to 'callback', turn it on until
        % finished with OutputFcn
        gui_HandleVisibility = get(gui_hFigure,'HandleVisibility');
        if strcmp(gui_HandleVisibility, 'callback')
            set(gui_hFigure,'HandleVisibility', 'on');
        end
        gui_Handles = guidata(gui_hFigure);
    else
        gui_Handles = [];
    end

    if nargout
        [varargout{1:nargout}] = feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
    else
        feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
    end

    if isscalar(gui_hFigure) && ishandle(gui_hFigure)
        set(gui_hFigure,'HandleVisibility', gui_HandleVisibility);
    end
end

function gui_hFigure = local_openfig(name, singleton, visible)

% openfig with three arguments was new from R13. Try to call that first, if
% failed, try the old openfig.
if nargin('openfig') == 2
    % OPENFIG did not accept 3rd input argument until R13,
    % toggle default figure visible to prevent the figure
    % from showing up too soon.
    gui_OldDefaultVisible = get(0,'defaultFigureVisible');
    set(0,'defaultFigureVisible','off');
    gui_hFigure = openfig(name, singleton);
    set(0,'defaultFigureVisible',gui_OldDefaultVisible);
else
    gui_hFigure = openfig(name, singleton, visible);
end

function result = local_isInvokeActiveXCallback(gui_State, varargin)

try
    result = ispc && iscom(varargin{1}) ...
             && isequal(varargin{1},gcbo);
catch
    result = false;
end

function result = local_isInvokeHGCallbak(gui_State, varargin)

try
    fhandle = functions(gui_State.gui_Callback);
    result = ~isempty(strfind(gui_State.gui_Name,fhandle.file)) || ...
             (ischar(varargin{1}) ...
             && isequal(ishandle(varargin{2}), 1) ...
             && (~isempty(strfind(varargin{1},[get(varargin{2}, 'Tag'), '_'])) || ...
                ~isempty(strfind(varargin{1}, '_CreateFcn'))) );
catch
    result = false;
end


