function varargout = sqdtool(varargin)
% SQDTOOL Scalar quantizer Design & Analysis Tool.
%      SQDTOOL is a Graphical User Interface (GUI) that allows you to
%      design and analyze scalar quantizer using Lloyd algorithm.
%      
%      If the DSP System Toolbox is installed, SQDTOOL realizes a model
%      with the scalar quantizer block and the design parameters (FINAL
%      CODEBOOK, FINAL BOUNDARY POINTS, SEARCHING METHOD, and TIE-BREAKING
%      RULE). FINAL CODEBOOK, FINAL BOUNDARY POINTS and mean square ERROR
%      at each iteration can also be exported to workspace, text file or
%      mat file (shortcut key: ctrl + E)
%
% See also: VQDTOOL

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

%   Copyright 1988-2023 The MathWorks, Inc.

% Begin initialization code - DO NOT EDIT
gui_Singleton = 0;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ... 
                   'gui_OpeningFcn', @sqdtool_OpeningFcn, ...
                   'gui_OutputFcn',  @sqdtool_OutputFcn, ...
                   'gui_LayoutFcn',  @sqdtool_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

% --------------------------------------------------------------------
function sqdtool_OpeningFcn(hObject, ~, handles, varargin) % eventdata
% This function has no output args, see OutputFcn.
% hObject    handle to figure (sqdtool.fig)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to sqdtool (see VARARGIN)

% Choose default command line output for sqdtool
handles.output = hObject; %

% Update handles structure
guidata(hObject, handles);
movegui(hObject, 'center');

% Set default title
set(handles.textStatus,'String','Initializing Scalar Quantizer Design Tool ...');

% Render menus
render_menus(hObject); 

% Render toolbar
set(hObject, 'Toolbar', 'none');
render_toolbar(hObject);

%set user data (ud)
ud=get(hObject,'UserData');
  ud.version = 2.0;% for backward compatibility
  ud.SQDTOOLidentifier = 1;
 
  ud.FileName='Untitled.sqd';% with path, Name and Extension
  ud.SaveOverwriteFlag=0;% first time - clicking save, calls saveas function
  ud.hTextStatus = handles.textStatus;% for export and realize block status change

  % ud for input to mex function
  ud.TS= 1:10; %randn(10000,1);
  ud.NumLevel=3;
  ud.initCB= [1 2 3]; 
  ud.initPT=[1.5 2.5];
  ud.RelTh  =1e-7;
  ud.MaxIter= 2147483647; %double(int32(inf));
  
  %pop-up values
  ud.popupSQSource        = 1;
  ud.popupInitPTSource    = 1;
  ud.popupStopCri         = 1;
  ud.popupSearchMeth      = 2; 
  ud.popupTieBreakRule    = 1;
  ud.popupDestMdl         = 1;
  ud.popupBlockType       = 1;% after version 2
  ud.chkboxOverwriteBlock = 0;   
  
  %for realize block, store the pop-up values corresponding to current plots.
  ud.popupSearchMethForCurrentFig   = ud.popupSearchMeth; 
  ud.popupTieBreakRuleForCurrentFig = ud.popupTieBreakRule;
  
  %change flags
  ud.TSchanged       = 0;
  ud.NumLevelchanged = 0;
  ud.initCBchanged   = 0;
  ud.initPTchanged   = 0;  
  ud.RelThchanged    = 0;
  ud.MaxIterchanged  = 0;
  
  ud.SQSourcechanged     = 0;
  ud.InitPTSourcechanged = 0;
  ud.StopCrichanged      = 0;
  ud.SearchMethchanged   = 0;
  ud.TieBreakRulechanged = 0; 
  
  % ud for error flag (to check if edit box entries are good)
  ud.errFlag_editTS       = 0;
  ud.errFlag_editNumLevel = 0;
  ud.errFlag_editInitCB   = 0;
  ud.errFlag_editInitPT   = 0;
  ud.errFlag_editRelTh    = 0;
  ud.errFlag_editMaxIter  = 0;
  
  % ud for storing outputs for 'Export'
  ud.finalCodebook= [-2.4520   -1.6422   -1.1864   -0.8196   -0.4923   -0.1728    0.0936    0.2977    0.4954    0.6928    0.9485 ...
                      1.2114    1.5586    1.9516    2.5323];
  ud.finalPartition=[ -2.0471   -1.4143   -1.0030   -0.6559   -0.3325   -0.0396    0.1957    0.3966    0.5941    0.8206 ...
                       1.0799    1.3850    1.7551    2.2420];
  ud.errorArray=[0.6238    0.1781    0.1129    0.0860    0.0704    0.0582    0.0502    0.0449    0.0413 ...
                 0.0385    0.0362    0.0338    0.0317    0.0304    0.0293    0.0283    0.0265    0.0241 ...
                 0.0224    0.0212    0.0204    0.0196    0.0186    0.0176    0.0171    0.0165    0.0158 ...
                 0.0153    0.0150    0.0148    0.0146    0.0145    0.0143    0.0142    0.0142    0.0141 ...
                 0.0140    0.0139    0.0138    0.0137    0.0137    0.0136    0.0134    0.0132    0.0130 ...
                 0.0128    0.0125    0.0123    0.0122    0.0119    0.0118    0.0118    0.0118    0.0117 ...
                 0.0117    0.0116    0.0116    0.0116    0.0116    0.0116    0.0115    0.0115    0.0115 ...
                 0.0115    0.0115    0.0115    0.0115    0.0115    0.0115    0.0115    0.0115    0.0115 ...
                 0.0115    0.0115    0.0115];%size=1x75
  
 % To save export window's values
  ud.exportTOpopup   = 1;%1/2/3
  ud.outputVarName   = {'finalCB','finalBP','Err'};
  ud.exportOverwrite = 0;%0=unchecked
  
set(hObject,'UserData',ud);  

if strcmp(get(hObject,'Visible'),'off')    
   % set Default enable/disable
   setenableprop([handles.textInitCB handles.editInitCB], 'off');
   setenableprop([handles.textInitPTSource handles.popupInitPTSource], 'off');
   setenableprop([handles.textInitPT handles.editInitPT], 'off');
   setenableprop([handles.textMaxIter handles.editMaxIter], 'off');
   setenableprop([handles.textDecBlkName   handles.editDecBlkName],    'off');
   set(handles.popupSearchMeth,'Value',2);
	
   % set color only for axes
   % default_grey_color = get(hObject,'Color');
   
   % set font size
   hfig1=handles.plotErrIter;  
   hfig2=handles.plotStepFcn;  

   if ~ispc
      hall = convert2vector(handles);
      set(hall(isprop(hall, 'fontsize')), 'fontsize', 10);
      hplots = [hfig1 hfig2];
      set(hplots(isprop(hplots, 'fontsize')), 'fontsize', 10);
   end
   
   %set tooltip string
   tooltipStrPushbutnRealMdl = sprintf('Generate model with the data\ncorresponding to the current figures');
   set(handles.pushbutnRealzMdl,'TooltipString',tooltipStrPushbutnRealMdl);
   tooltipStrPushbutnExport  = sprintf('Export data corresponding\nto the current figures');
   set(handles.pushbutnExport,'TooltipString',tooltipStrPushbutnExport);
   tooltipStrPushbutnPlot    = sprintf('Design the scalar quantizer\nand update the figures');
   set(handles.pushbutnPlotFig,'TooltipString',tooltipStrPushbutnPlot);
   
   %%%%%%%%%%%%%%%%%%%%%%%%%% Plot error%%%%%%%%%%%%%%%%%%%%
   axes(hfig1);
   e=ud.errorArray;
  
   h_line=plot(e);
   xlabel('Number of Iterations');
   ylabel('Mean Square Error');
   set(h_line,'ButtonDownFcn',@sqsetdatamarkers);% always call after setting axes, xlabel and ylabel, and plot command
   grid on;
   %%%%%%%%%%%%%%%%%% Plot step function %%%%%%%%%%%%%%%%%%%
   axes(hfig2);
   p_new =[-3.3128   -2.6800   ud.finalPartition    2.2420    2.7289    3.2157];
   c_new =[-2.4520   ud.finalCodebook    2.5323    2.5323    2.5323];
   c_LowLimit =  -3.2619;
   c_UpLimit  =   3.1131;
   p_LowLimit =  -3.3128;
   p_UpLimit  =   3.2157;
   h_line=stairs(p_new, c_new);
   set(hfig2,'YLim',[c_LowLimit c_UpLimit]);
   set(hfig2,'XLim',[p_LowLimit p_UpLimit]);
  
   xlabel('Final Boundary Points (theoretical bounds are -inf & +inf)');
   ylabel('Final Codewords');
   set(h_line,'ButtonDownFcn',@sqsetdatamarkers);% always call after setting axes, xlabel and ylabel, and plot command
   set(handles.pushbutnRealzMdl,'string','Generate Block');
   set(handles.pushbutnExport,'string','Export Outputs...'); 
   grid on;
   set(handles.textStatus,'String','Ready');
end

% --------------------------------------------------------------------
function render_menus(fig)

% Render the "File" menu
% hmenus.hfile = render_sqfilemenu(fig, 1);
render_sqfilemenu(fig, 1);

% Render the "Edit" menu
% hmenus.hedit = render_spteditmenu(fig);
render_spteditmenu(fig);

% Render the "Insert" menu
% hmenus.hinsert = render_sptinsertmenu(fig,3);
render_sptinsertmenu(fig,3);

% Render the "Tools" menu
% hmenus.htools = render_spttoolsmenu(fig,4);
render_spttoolsmenu(fig,4);

% Render the "Window" menu
% hmenus.hwindow = render_sptwindowmenu(fig,5);
render_sptwindowmenu(fig,5);

% Render the "Help" menu
% hmenus.hhelp = render_sqhelpmenu(fig, 6);
render_sqhelpmenu(fig, 6);

%-------------------------------------------------------------------
function render_toolbar(fig)

htoolbar.htoolbar = uitoolbar('Parent',fig);

% Render the print buttons (New, open, save, Print, Prinpreview)
% htoolbar.hprintbtns = render_sqprintbtns(htoolbar.htoolbar, fig);
render_sqprintbtns(htoolbar.htoolbar, fig);

% Render the annotation buttons (Edit Plot, Insert Text,Insert Arrow, Insert Line)
% htoolbar.hscribebtns = render_sptscribebtns(htoolbar.htoolbar);
render_sptscribebtns(htoolbar.htoolbar);

% Render the zoom buttons (Zoom In, Zoom Out)
% htoolbar.hzoombtns = render_zoombtns(fig);
render_zoombtns(fig);

%-------------------------------------------------------------------
function varargout = sqdtool_OutputFcn(~, ~, handles) % hObject, eventdata, handles
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

% --------------------------------------------------------------------
function pushbutnPlotFig_Callback(~, ~, handles) % callback
% hObject    handle to pushbutnPlotFig (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

localStartEndProcessing (handles,'off','Pre-processing ...','Arrow');

% The following function checks if the ud has changed (it doesn't evaluate
% edit box entries). So it doesn't catch the changes made in workspace.
need_newQuantizer_before = sqDataChanged(handles);

% need to verify user-defined initPT with respect to user-defined initCB
% If the user gives valid initPT (the callback validates it against iniCB)
% Now if the user changes initCB (its callback doesn't validate it
% against initPT), no way to chatch the error from initCB callback.
% So check it here
sqCallAllCallbacks(handles); %updates ud, so catches changes made in workspace

% If there is no changes in workspace data, then the above call sets all changes to zero
% so for no workspace changes  need_newQuantizer_after = 0 always
need_newQuantizer_after = sqDataChanged(handles);

% check if any of FINAL edit box entry is invalid (including workspace changes)
[errorStatus, errorString] = sqgeterrorstatusandstring(handles);


if (errorStatus)
    errordlg(errorString);
    localStartEndProcessing (handles,'on','Ready', 'Arrow');
    return
else
    % get autogenerated initCB (with numLevel), autogenerated initPT, RelTh, MaxIter
    % for user defined case, do nothing
    sqResetChangeFlags(handles);% this function resets ud's change flags to zero
    % AutoGenerateInitCB  = (get(handles.popupSQSource,'Value')==1);
    % AutoGenerateInitPT  = (~AutoGenerateInitCB)&&(get(handles.popupInitPTSource,'Value')==1);
    
    try
        sqcalculateandsetundefined_ud(handles);% this function updates the user data
    catch me
        errordlg([me.message ' Consider reducing the Number of levels.']);
        localStartEndProcessing (handles,'on','Ready', 'Arrow');
        return;
    end
    hfig=handles.sqdtool;
    ud=get(hfig,'UserData');
    if (~(need_newQuantizer_before||need_newQuantizer_after))
        ButtonName=questdlg('The input parameters for the scalar quantizer have not been updated. Do you want to design it again?');
        if ~strcmpi(ButtonName,'Yes')
            localStartEndProcessing (handles,'on','Ready', 'Arrow');
            return
        end
    end
    
    localStartEndProcessing (handles,'off','Processing ...', 'Watch');
    
    % call mex file
    %ud.popupSearchMeth, ud.popupTieBreakRule <-- values 1 or 2
    [finalCB, finalPT, ErrArray] = ...
        dspsqdesignmex(ud.TS, ud.initCB, ud.initPT, ud.RelTh, ...
        ud.MaxIter, ud.popupSearchMeth, ud.popupTieBreakRule);
    
    hMainFig=handles.sqdtool;
    ud2=get(hMainFig,'UserData');
    ud2.finalCodebook  = finalCB;
    ud2.finalPartition = finalPT;
    ud2.errorArray     = ErrArray;
    ud2.popupSearchMethForCurrentFig   = ud.popupSearchMeth;
    ud2.popupTieBreakRuleForCurrentFig = ud.popupTieBreakRule;
    set(hMainFig,'UserData',ud2);
    
    % update the export dialog, if it exists
    if isappdata(hMainFig,'sqExportDialog')
        hXP = getappdata(hMainFig,'sqExportDialog');
        set(hXP,'Data',{finalCB(:) finalPT(:) ErrArray(:)});
    end
    
    % every time you update plot, you make it dirty.
    sqmake_fig_dirty(hMainFig);
    
    % update Total number of iterations Text
    h_editTotalIter=handles.editTotalIter;
    set(h_editTotalIter,'String',num2str(length(ErrArray)));
    
    %%%%%%%%%%%%%%% PLOT ERROR %%%%%%%%%%%%%%%%%%%%%
    sqplot_error(handles.plotErrIter, ErrArray);
    
    %%%%%%%%%%%%%%% PLOT STEP FUNCTION %%%%%%%%%%%%%%%%%%%%%
    sqplot_stairs (handles.plotStepFcn, finalCB, finalPT);
    
    localStartEndProcessing (handles,'on','Ready', 'Arrow');
end

% --------------------------------------------------------------------
function need_newQuantizer = sqDataChanged(handles)

 ud=get(handles.sqdtool,'UserData');
  AutoGenerateInitCB  = (get(handles.popupSQSource,'Value')==1);
  AutoGenerateInitPT  = (~AutoGenerateInitCB)&&(get(handles.popupInitPTSource,'Value')==1);
  StopCriteriaRelTh   = (get(handles.popupStopCri,'Value')==1);
  StopCriteriaMaxIter = (get(handles.popupStopCri,'Value')==2);

 need_newQuantizer = (ud.TSchanged                                              || ...
                     ud.SQSourcechanged                                         || ...
                     (( AutoGenerateInitCB) && ud.NumLevelchanged)              || ...
                     ((~AutoGenerateInitCB) && ud.initCBchanged)                || ...
                     ((~AutoGenerateInitCB) && ud.InitPTSourcechanged)          || ...
                     ((~AutoGenerateInitCB  && ~AutoGenerateInitPT) && ud.initPTchanged) || ... 
                     ud.StopCrichanged                                          || ...
                     ((~StopCriteriaMaxIter)&& ud.RelThchanged)                 || ...
                     ( (~StopCriteriaRelTh) && ud.MaxIterchanged)               || ...
                     ud.TieBreakRulechanged                                     || ...
                     ud.SearchMethchanged                                       || ...
                     (ud.popupSearchMethForCurrentFig   ~= ud.popupSearchMeth ) || ...
                     (ud.popupTieBreakRuleForCurrentFig ~= ud.popupTieBreakRule) );

% --------------------------------------------------------------------
function sqResetChangeFlags(handles)

    hFig = handles.sqdtool;
    ud=get(hFig,'UserData');
		ud.TSchanged           = 0;
		ud.SQSourcechanged     = 0;
		ud.NumLevelchanged     = 0;
		ud.initCBchanged       = 0;
		ud.InitPTSourcechanged = 0;
		ud.initPTchanged       = 0;
		ud.StopCrichanged      = 0;
		ud.RelThchanged        = 0;
		ud.MaxIterchanged      = 0;
		ud.TieBreakRulechanged = 0;
		ud.SearchMethchanged   = 0; 
	set(hFig,'UserData',ud);               

% --------------------------------------------------------------------
function localStartEndProcessing (handles, EnableState, StatusText, MouserPointer)

 %EnableState = 'on' or 'off'
 %StatusText = 'Ready' or 'Processing ...' 
 %MouserPointer = 'Arror' or 'Watch'
 set(handles.pushbutnPlotFig,'Enable',EnableState);% disable the pushbutnPlotFig
 set(handles.textStatus,'ForeGroundColor','Black');
 set(handles.textStatus, 'String',StatusText); %change the status text
 setptr(handles.sqdtool, MouserPointer); % set mouse pointer to hourglass

% --------------------------------------------------------------------
function flag = TSminmaxSame(TSval)
  size_val = size(TSval);
  TSisMatrix = (size_val(1)>1 && size_val(2)>1);
  if (TSisMatrix)
      minTS = min(min(TSval));
      maxTS = max(max(TSval));
  else
      minTS = min(TSval);
      maxTS = max(TSval);
  end
  flag = (minTS == maxTS);
 
% --------------------------------------------------------------------
function editTS_Callback(hObject, eventdata, handles)

% hObject    handle to editTS (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if nargin>3, return; end
hfig=handles.sqdtool;
if (isobject(eventdata))
    sqmake_fig_dirty(hfig);
    set(handles.textStatus,'ForeGroundColor','Black');
    set(handles.textStatus,'String','Ready');
end % make fig dirty
ud=get(hfig,'UserData');

[val, errStr] = evaluatevars(get(hObject, 'String'));

if isempty(errStr)
    val=double(val);
    size_val = size(val);
    width_val = size_val(1)*size_val(2);
    if ~isreal(val)
        if (isobject(eventdata)), errordlg('The TRAINING SET must be non-complex.'); end
        ud.errFlag_editTS = 1;
    elseif width_val<2
        if (isobject(eventdata)), errordlg('The TRAINING SET must have length greater than one.'); end
        ud.errFlag_editTS = 1;
    elseif TSminmaxSame(val)
        if (isobject(eventdata)), errordlg('The TRAINING SET must have at least two unique elements.'); end
        ud.errFlag_editTS = 1;        
    else
       %set changeFlag only if TS is valid and different from the previous entry
       ud.TSchanged = 0;
       if ~isequal(ud.TS,val)     
           ud.TSchanged = 1; 
       end
       % Update userdata
       ud.errFlag_editTS = 0; 
       ud.TS = val;% save edit box entry in ud
    end
else
    ud.errFlag_editTS = 1;
    errStr = strcat(errStr,' (Error from TRAINING SET edit box.)');
    if (isobject(eventdata))
        errordlg(errStr);
    end
end
set(hfig,'UserData',ud);

% --------------------------------------------------------------------
function popupSQSource_Callback(hObject, eventdata, handles) 
% hObject    handle to popupSQSource (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

set(handles.textStatus,'ForeGroundColor','Black');  set(handles.textStatus,'String','Ready');
val = get(hObject,'Value');  
if (val==1)%% auto-generate initCB
	setenableprop([handles.textNumLevel   handles.editNumLevel],    'on');
    editNumLevel_Callback(handles.editNumLevel, eventdata, handles);% update ud.NumLevel, makes fig dirty
    setenableprop([handles.textInitCB     handles.editInitCB],      'off');
	setenableprop([handles.textInitPTSource handles.popupInitPTSource], 'off');
	setenableprop([handles.textInitPT     handles.editInitPT],      'off');
else%% user-defined initCB
	setenableprop([handles.textNumLevel   handles.editNumLevel],    'off');
	setenableprop([handles.textInitCB     handles.editInitCB],      'on');
    editInitCB_Callback(handles.editInitCB, eventdata, handles);% update ud.initCB, makes fig dirty
    setenableprop([handles.textInitPTSource handles.popupInitPTSource], 'on');
    popupInitPTSource_Callback(handles.popupInitPTSource, eventdata, handles);% update ud.popupInitPTSource
end   

hfig=handles.sqdtool;
ud=get(hfig,'UserData');

ud.SQSourcechanged = 0;
if ud.popupSQSource ~= val
     ud.SQSourcechanged = 1;
end

ud.popupSQSource = val;
set(hfig,'UserData',ud);
if nargin>3, return; end

% --------------------------------------------------------------------
function editNumLevel_Callback(hObject, eventdata, handles)
% hObject    handle to editNumLevel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if nargin>3, return; end
hfig=handles.sqdtool;
if (isobject(eventdata))
    sqmake_fig_dirty(hfig); 
    set(handles.textStatus,'ForeGroundColor','Black');
    set(handles.textStatus,'String','Ready');
end% make fig dirty
ud=get(hfig,'UserData'); 

[val, errStr] = evaluatevars(get(hObject, 'String'));

if isempty(errStr)
    val=double(val);
    if ~isreal(val)   
        if (isobject(eventdata))
            errordlg('The NUMBER OF LEVELS must be non-complex.');
        end
        ud.errFlag_editNumLevel = 1;
    elseif (isempty(val) || ~isscalar(val)  || val < 2 || val >= double(intmax('int32')) || (val-floor(val)~=0))
        if (isobject(eventdata)), errordlg('The NUMBER OF LEVELS must be a positive scalar integer (greater than 1 and less than intmax(''int32'')).'); end
        ud.errFlag_editNumLevel = 1;
    else
        ud.NumLevelchanged = 0;
        %set changeFlag only if NumLevel is valid and different from the previous entry
        if ud.NumLevel~= val
            ud.NumLevelchanged = 1; 
        end
        ud.errFlag_editNumLevel = 0;
        ud.NumLevel = val;
    end 
else
    errStr = strcat(errStr,' (Error from NUMBER OF LEVELS edit box.)');
    if (isobject(eventdata)), errordlg(errStr); end
    ud.errFlag_editNumLevel = 1;
end
set(hfig,'UserData',ud);

% --------------------------------------------------------------------
function editInitCB_Callback(hObject, eventdata, handles)
% hObject    handle to editInitCB (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if nargin>3, return; end
hfig=handles.sqdtool;
if (isobject(eventdata))
    sqmake_fig_dirty(hfig); 
    set(handles.textStatus,'ForeGroundColor','Black');  set(handles.textStatus,'String','Ready');
end% make fig dirty
ud=get(hfig,'UserData');
[val, errStr] = evaluatevars(get(hObject, 'String'));

if isempty(errStr)
    val=double(val);
    [m, n] = size(val);
    isCBmatrix = (m>1) && (n>1);
    if ~isreal(val)
        if (isobject(eventdata)), errordlg('The INITIAL CODEBOOK must be non-complex.'); end
        ud.errFlag_editInitCB = 1;   
    elseif  isCBmatrix
        if (isobject(eventdata)), errordlg('The INITIAL CODEBOOK must be a vector.'); end
        ud.errFlag_editInitCB = 1;
    elseif length(val)<2
        if (isobject(eventdata)), errordlg('The INITIAL CODEBOOK set must have length greater than one.'); end
        ud.errFlag_editInitCB = 1;
    else
       %set changeFlag only if initCB is valid and different from the previous entry
       val=sort(val);% get SORTED initCB
       ud.initCBchanged = 0;
       if ~isequal(ud.initCB, val)
           ud.initCBchanged = 1; 
       end
       % Update userdata
       ud.initCB = val;%always store sorted initCB
       ud.errFlag_editInitCB = 0;
    end    
else
    if (isobject(eventdata)), errordlg([errStr,' (Error from INITIAL CODEBOOK edit box.)']); end
    ud.errFlag_editInitCB = 1;
end
set(hfig,'UserData',ud);

% --------------------------------------------------------------------
function editInitPT_Callback(hObject, eventdata, handles)
% hObject    handle to editInitPT (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if nargin>3, return; end
hfig=handles.sqdtool;
if (isobject(eventdata))
    sqmake_fig_dirty(hfig); 
    set(handles.textStatus,'ForeGroundColor','Black');  set(handles.textStatus,'String','Ready');
end% make fig dirty
ud=get(hfig,'UserData');

[val, errStr] = evaluatevars(get(hObject, 'String'));

if isempty(errStr)
    val=double(val);
    [m, n] = size(val);
    isPTmatrix = (m>1 && n>1);
    if ~isreal(val)
        if (isobject(eventdata)), errordlg('The INITIAL BOUNDARY POINTS must be non-complex.'); end
        ud.errFlag_editInitPT = 1;    
    elseif  isPTmatrix
        if (isobject(eventdata)), errordlg('The INITIAL BOUNDARY POINTS must be a vector.'); end
        ud.errFlag_editInitPT = 1;
    elseif (length(val)~= (length(ud.initCB)-1))
        if (isobject(eventdata)), errordlg('The INITIAL BOUNDARY POINTS vector length must be one less than the INITIAL CODEBOOK length.'); end
        ud.errFlag_editInitPT = 1;
    else
       if (ud.errFlag_editInitCB)
           if (isobject(eventdata)), errordlg('Invalid INITIAL CODEBOOK'); end
       else           
           errFlagRegularSQ = InitCBandInitPTforRegularSQ(handles.editInitCB, handles.editInitPT);
           % this requires that initCB, initPT must be sorted and interleaved
            if (errFlagRegularSQ)%InitCBandInitPTforRegularSQ(h_editInitCB, h_initPT)
                str1 = 'If INITIAL BOUNDARY POINTS = [p(1) p(2) p(3) ... p(N-1)] and INITIAL CODEBOOK = [c(1) c(2) c(3) ... C(N)] ';
                str2 = ' then for a regular quantizer c(1) < p(1) < c(2) < p(2) ...p(N-2) < c(N-1) < p(N-1) < c(N).';
                if (isobject(eventdata)), errordlg(strcat(str1,str2)); end
                ud.errFlag_editInitPT = 1;
            else
                %set changeFlag only if initCB is valid and different from the previous entry
                ud.initPTchanged = 0;
                if ~isequal(ud.initPT, val)
                    ud.initPTchanged = 1; 
                end
                % Update userdata 
                ud.initPT = val;%sortedVal;        
                ud.errFlag_editInitPT = 0;
            end
        end            
    end
else
    errStr = strcat(errStr,' (Error from INITIAL BOUNDARY POINTS edit box.)');
    if (isobject(eventdata)), errordlg(errStr); end 
    ud.errFlag_editInitPT = 1;
end
set(hfig,'UserData',ud);


% --------------------------------------------------------------------
function popupInitPTSource_Callback(hObject, ~, handles) % eventdata
% hObject    handle to popupInitPTSource (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

set(handles.textStatus,'ForeGroundColor','Black');  set(handles.textStatus,'String','Ready');
val = get(hObject,'Value');
hfig=handles.sqdtool;
if (val==1) %% auto-generate initPT
	setenableprop([handles.textInitPT   handles.editInitPT],    'off');
    sqmake_fig_dirty(hfig); 
else %%user-defined initPT
	setenableprop([handles.textInitPT   handles.editInitPT],    'on');
    editInitPT_Callback(handles.editInitPT, 1, handles);% make_fig_dirty
end   

ud=get(hfig,'UserData');

ud.InitPTSourcechanged = 0;
if ud.popupInitPTSource ~= val
     ud.InitPTSourcechanged = 1;
end

ud.popupInitPTSource = val;    
set(hfig,'UserData',ud);
if nargin>3, return; end

% --------------------------------------------------------------------
function popupStopCri_Callback(hObject, eventdata, handles)
% hObject    handle to popupStopCri (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

set(handles.textStatus,'ForeGroundColor','Black');  set(handles.textStatus,'String','Ready');
val = get(hObject,'Value');
if (val==1)%% stop-criteria: Threshold
	setenableprop([handles.textMaxIter   handles.editMaxIter],    'off');
    setenableprop([handles.textRelTh     handles.editRelTh],    'on');
    editRelTh_Callback(handles.editRelTh, eventdata, handles);% update ud.MaxIter, makes fig dirty  
elseif (val==2)%% stop-criteria: MaxIter 
	setenableprop([handles.textRelTh     handles.editRelTh],    'off');
    setenableprop([handles.textMaxIter   handles.editMaxIter],    'on');
    editMaxIter_Callback(handles.editMaxIter, eventdata, handles);% update ud.MaxIter, makes fig dirty      
else%% stop-criteria: Threshold || MaxIter 
	setenableprop([handles.textRelTh     handles.editRelTh],    'on');
    editRelTh_Callback(handles.editRelTh, eventdata, handles);% update ud.MaxIter, makes fig dirty 
    setenableprop([handles.textMaxIter   handles.editMaxIter],    'on');
    editMaxIter_Callback(handles.editMaxIter, eventdata, handles);% update ud.MaxIter, makes fig dirty  
end   

hfig=handles.sqdtool;
ud=get(hfig,'UserData');

ud.StopCrichanged = 0;
if ud.popupStopCri ~= val
     ud.StopCrichanged = 1;
end

ud.popupStopCri = val;    
set(hfig,'UserData',ud);
if nargin>3, return; end

% --------------------------------------------------------------------
function editRelTh_Callback(hObject, eventdata, handles)
% hObject    handle to editRelTh (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if nargin>3, return; end
hfig=handles.sqdtool;
if (isobject(eventdata))
    sqmake_fig_dirty(hfig); 
    set(handles.textStatus,'ForeGroundColor','Black');  set(handles.textStatus,'String','Ready');
end% make fig dirty
ud=get(hfig,'UserData');

[val, errStr] = evaluatevars(get(hObject, 'String'));

if isempty(errStr)
    val=double(val);
    if ~isreal(val)
        if (isobject(eventdata))
            errordlg('The RELATIVE THRESHOLD must be non-complex.');
        end
        ud.errFlag_editRelTh = 1;
    elseif (~isscalar(val) || val>=1 || val<0) % Valid values: 0 <= RelTh < 1
        if (isobject(eventdata))
            errordlg('The RELATIVE THRESHOLD must be a scalar - greater than or equal to 0 and less than 1.');
        end
        ud.errFlag_editRelTh = 1;    
    else
        ud.RelThchanged = 0;
        %set changeFlag only if RelTh is valid and different from the previous entry
        if ud.RelTh~= val
            ud.RelThchanged = 1; 
        end
		% Update userdata
        ud.RelTh = val;
        ud.errFlag_editRelTh = 0;
    end 
else
    errStr = strcat(errStr,' (Error from RELATIVE THRESHOLD edit box.)');
    if (isobject(eventdata))
        errordlg(errStr);
    end
    ud.errFlag_editRelTh = 1;
end
set(hfig,'UserData',ud);

% --------------------------------------------------------------------
function editMaxIter_Callback(hObject, eventdata, handles)
% hObject    handle to editMaxIter (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if nargin>3
    return;
end
hfig=handles.sqdtool;
if (isobject(eventdata))
    sqmake_fig_dirty(hfig); 
    set(handles.textStatus,'ForeGroundColor','Black');  set(handles.textStatus,'String','Ready');
end % make fig dirty
ud=get(hfig,'UserData'); 

[val, errStr] = evaluatevars(get(hObject, 'String'));

if isempty(errStr)
    val=double(val);
    if ~isreal(val)
        if (isobject(eventdata))
            errordlg('The MAXIMUM ITERATION must be non-complex.');
        end
        ud.errFlag_editMaxIter = 1;
    elseif (~isscalar(val)  || val <=1 || (val-floor(val)~=0))
        if (isobject(eventdata))
            errordlg('The MAXIMUM ITERATION must be a positive scalar integer greater than 1.');
        end
        ud.errFlag_editMaxIter = 1;    
    else
        ud.MaxIterchanged = 0;
        %set changeFlag only if RelTh is valid and different from the previous entry
        if ud.MaxIter~= val
            ud.MaxIterchanged = 1; 
        end
		% Update userdata
	    ud.MaxIter = val;
	    ud.errFlag_editMaxIter = 0; 
    end
else
    errStr = strcat(errStr,' (Error from MAXIMUM ITERATION edit box.)');
    if (isobject(eventdata))
        errordlg(errStr);
    end
    ud.errFlag_editMaxIter = 1;
end
set(hfig,'UserData',ud);

% --------------------------------------------------------------------
function popupSearchMeth_Callback(hObject, ~, handles)
% hObject    handle to popupSearchMeth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

set(handles.textStatus,'ForeGroundColor','Black');  set(handles.textStatus,'String','Ready');
val = get(hObject,'Value');

hfig=handles.sqdtool;
sqmake_fig_dirty(hfig);
ud=get(hfig,'UserData');

ud.SearchMethchanged = 0;
if ud.popupTieBreakRule ~= val
     ud.SearchMethchanged = 1;
end

ud.popupSearchMeth = val;    
set(hfig,'UserData',ud);
if nargin>3, return; end

% --------------------------------------------------------------------
function popupTieBreakRule_Callback(hObject, ~, handles)
% hObject    handle to popupTieBreakRule (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

set(handles.textStatus,'ForeGroundColor','Black');  set(handles.textStatus,'String','Ready');
val = get(hObject,'Value');

hfig=handles.sqdtool;
sqmake_fig_dirty(hfig); 
ud=get(hfig,'UserData');

ud.TieBreakRulechanged = 0;
if ud.popupTieBreakRule ~= val
     ud.TieBreakRulechanged = 1;
end

ud.popupTieBreakRule = val;    
set(hfig,'UserData',ud);
if nargin>3, return; end

% --------------------------------------------------------------------
function pushbutnRealzMdl_Callback(~, ~, handles)
% hObject    handle to pushbutnRealzMdl (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
  hfig=handles.sqdtool;
  ud=get(hfig,'UserData');
  UD.finalCodebook    = ud.finalCodebook;
  UD.finalPartition   = ud.finalPartition;
  UD.errorArray       = ud.errorArray;
  UD.destinationMdl   = get(handles.popupDestMdl,'Value');% 1=current, 2=new
  UD.SearchMethod     = ud.popupSearchMethForCurrentFig; 
  UD.TieBreakingRule  = ud.popupTieBreakRuleForCurrentFig;
  UD.system           = '';
  UD.overwriteFlag    = get(handles.chkboxOverwriteBlock, 'Value');% 0/1 
  UD.hTextStatus      = ud.hTextStatus;

  if (ud.version==1.0)% no pop-up to choose encoder or decoder; so set it to both
      UD.blockName        = get(handles.editBlockName, 'String');
      UD.blockType        = 3;% 1=encoder, 2=decoder, 3=both  
      if (UD.blockType ~=2)%encoder(1) OR both(3)
          UD.blockName  = [UD.blockName '_encoder'];
          UD.whichBlock = 1; %encoder
          sqrealizemdl(UD);% this sets status to ready
      end      
      if (UD.blockType~=1)%decoder(2) OR both(3)
          if (UD.blockType==3)
              UD.destinationMdl=1;
          end %1=current
          UD.blockName  = [UD.blockName '_decoder'];
          UD.whichBlock = 2; %decoder
          sqrealizemdl(UD);% this sets status to ready
      end
  else % ud.version==2.0    
      UD.blockType        = get(handles.popupBlockType,'Value');% 1=encoder, 2=decoder, 3=both  
      if (UD.blockType ~=2)%encoder(1) OR both(3)
          UD.blockName  = get(handles.editEncBlkName, 'String');
          UD.whichBlock = 1; %encoder
          sqrealizemdl(UD);% this sets status to ready
      end      
      if (UD.blockType~=1)%decoder(2) OR both(3)
          if (UD.blockType==3)
              UD.destinationMdl=1;
          end %1=current
          UD.blockName  = get(handles.editDecBlkName, 'String');
          UD.whichBlock = 2; %decoder
          sqrealizemdl(UD);% this sets status to ready
      end
  end    
  
% --------------------------------------------------------------------
function errFlagRegularSQ = InitCBandInitPTforRegularSQ(h_editInitCB, h_editInitPT)
 initCB = evaluatevars(get(h_editInitCB, 'String'));
 initPT = evaluatevars(get(h_editInitPT, 'String'));
 errFlagRegularSQ = 0;
 for i= 1:length(initCB)-1
     if initCB(i)>=initPT(i) || ...
             initPT(i)>= initCB(i+1)
         %%'If INITIAL BOUNDARY POINTS = [p(1) p(2) p(3) ... p(N-1)] and INITIAL CODEBOOK = [c(1) c(2) c(3) ... C(N)] ';
         %%' then for a regular quantizer c(1) < p(1) < c(2) < p(2) ...p(N-2) < c(N-1) < p(N-1) < c(N).';
         errFlagRegularSQ  = 1; 
         break;
     end
end

% --------------------------------------------------------------------
function popupDestMdl_Callback(hObject, ~, handles)
% hObject    handle to popupDestMdl (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

set(handles.textStatus,'ForeGroundColor','Black');  set(handles.textStatus,'String','Ready');
val = get(hObject,'Value');  
if (val==1)%% current model
	setenableprop(handles.chkboxOverwriteBlock,  'on');
    set(handles.pushbutnRealzMdl,'string','Generate Block');
else%% new model
	setenableprop(handles.chkboxOverwriteBlock,  'off');
    set(handles.pushbutnRealzMdl,'string','Generate Model');
end   
hfig=handles.sqdtool;
sqmake_fig_dirty(hfig);
ud=get(hfig,'UserData');
ud.popupDestMdl = val;
set(hfig,'UserData',ud);
if nargin>3, return; end

% --------------------------------------------------------------------
function editBlockName_Callback(~, ~, handles)
% hObject    handle to editBlockName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% this function is for version number: 1 (not used in version number 2)

set(handles.textStatus,'ForeGroundColor','Black');  set(handles.textStatus,'String','Ready');
hfig=handles.sqdtool;
sqmake_fig_dirty(hfig); 

% --------------------------------------------------------------------
function chkboxOverwriteBlock_Callback(hObject, ~, handles)
% hObject    handle to chkboxOverwriteBlock (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

set(handles.textStatus,'ForeGroundColor','Black');  set(handles.textStatus,'String','Ready');
hfig=handles.sqdtool;
sqmake_fig_dirty(hfig);
ud=get(hfig,'UserData');
ud.chkboxOverwriteBlock = get(hObject,'Value');
set(hfig,'UserData',ud);

%--------------------------------------------------------------------------
function pushbutnExport_Callback(~, ~, handles)
% hObject    handle to pushbutnExport (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

sqexport(handles.sqdtool);% This sets status to ready

%--------------------------------------------------------------------------
function sqCallAllCallbacks(handles)
  % User Data are not updated here (no SET)
  AutoGenerateInitCB  = (get(handles.popupSQSource,'Value')==1);
  AutoGenerateInitPT  = (~AutoGenerateInitCB)&&(get(handles.popupInitPTSource,'Value')==1);
  StopCriteriaRelTh   = (get(handles.popupStopCri,'Value')==1);
  StopCriteriaMaxIter = (get(handles.popupStopCri,'Value')==2);
  
  editTS_Callback(handles.editTS, 1, handles);
  if (AutoGenerateInitCB)
      editNumLevel_Callback(handles.editNumLevel, 1, handles);
  else
      editInitCB_Callback(handles.editInitCB, 1, handles);
      if (~AutoGenerateInitPT)   
          editInitPT_Callback(handles.editInitPT, 1, handles);
      end
  end
  if (~StopCriteriaMaxIter)
      editRelTh_Callback(handles.editRelTh, 1, handles);
  end
  if (~StopCriteriaRelTh)
      editMaxIter_Callback(handles.editMaxIter, 1, handles);
  end   
  
% --------------------------------------------------------------------
function updateWarningError(~, ~, handles,str)
set(handles.textStatus,'ForegroundColor','Red','String',str)

% --------------------------------------------------------------------
function updateStatus(~, ~, handles,str)
set(handles.textStatus,'ForegroundColor','Black','String',str)  

% --------------------------------------------------------------------
function sqdtool_CloseRequestFcn(hObject, ~, ~)
% hObject    handle to sqdtool (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if isappdata(hObject,'sqExportDialog')
    hXP = getappdata(hObject,'sqExportDialog');
    close(hXP);
end

sqclose(hObject);

% --------------------------------------------------------------------------
function editDecBlkName_Callback(~, ~, handles)
% hObject    handle to editDecBlkName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% for version: 2

set(handles.textStatus,'ForeGroundColor','Black');  
set(handles.textStatus,'String','Ready');
hfig=handles.sqdtool;
sqmake_fig_dirty(hfig); 

% --------------------------------------------------------------------------
function editEncBlkName_Callback(~, ~, handles)
% hObject    handle to editEncBlkName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% for version: 2

set(handles.textStatus,'ForeGroundColor','Black');  set(handles.textStatus,'String','Ready');
hfig=handles.sqdtool;
sqmake_fig_dirty(hfig); 

% --------------------------------------------------------------------------
function popupBlockType_Callback(hObject, ~, handles)
% hObject    handle to popupBlockType (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% for version: 2

set(handles.textStatus,'ForeGroundColor','Black');  set(handles.textStatus,'String','Ready');
val = get(hObject,'Value');  
if (val==1)%% Encoder
    setenableprop([handles.textEncBlkName   handles.editEncBlkName],    'on');
	setenableprop([handles.textDecBlkName   handles.editDecBlkName],    'off');
elseif (val==2)%% Decoder
	setenableprop([handles.textEncBlkName   handles.editEncBlkName],    'off');
	setenableprop([handles.textDecBlkName   handles.editDecBlkName],    'on');
else%% Both
	setenableprop([handles.textEncBlkName   handles.editEncBlkName],    'on');
	setenableprop([handles.textDecBlkName   handles.editDecBlkName],    'on');   
end     
hfig=handles.sqdtool;
sqmake_fig_dirty(hfig);
ud=get(hfig,'UserData');
ud.popupBlockType = val;  
set(hfig,'UserData',ud);


% --- Creates and returns a handle to the GUI figure. 
function h1 = sqdtool_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
%load sqdtool.mat
mat{1} = struct('isDirty', 0, 'getFrame' ,0);
mat{2} = @setdatamarkers;
mat{3} = @setdatamarkers;

appdata = [];
appdata.GUIDEOptions = struct(...
    'active_h', [], ...
    'taginfo', struct(...
    'figure', 2, ...
    'axes', 14, ...
    'pushbutton', 15, ...
    'popupmenu', 28, ...
    'frame', 18, ...
    'edit', 36, ...
    'text', 89, ...
    'checkbox', 5), ...
    'override', 1, ...
    'release', 13, ...
    'resize', 'simple', ...
    'accessibility', 'callback', ...
    'mfile', 1, ...
    'callbacks', 1, ...
    'singleton', 0, ...
    'syscolorfig', 1, ...
    'blocking', 0);
appdata.lastValidTag = 'sqdtool';
appdata.GUIDELayoutEditor = mat{1};

h1 = figure(...
'Units','characters',...
'Position',[37.6666666666667 10.6666666666667 166.166666666667 50.5],...
'Visible',get(0,'defaultfigureVisible'),...
'Color',[0.929411764705882 0.929411764705882 0.929411764705882],...
'CloseRequestFcn','sqdtool(''sqdtool_CloseRequestFcn'',gcf,[],guidata(gcf))',...
'IntegerHandle','off',...
'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],...
'MenuBar','none',...
'Name','SQ Design Tool - [Untitled.sqd]',...
'NumberTitle','off',...
'HandleVisibility','callback',...
'Tag','sqdtool',...
'UserData',struct(...
    'version', 1, ...
    'SQDTOOLidentifier', 1),...
'PaperPosition',get(0,'defaultfigurePaperPosition'),...
'InvertHardcopy',get(0,'defaultfigureInvertHardcopy'),...
'ScreenPixelsPerInchMode','manual',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h2 = axes(...
'Parent',h1,...
'CameraPosition',[40 0.35 17.3205080756888],...
'CameraPositionMode',get(0,'defaultaxesCameraPositionMode'),...
'CameraTarget',[40 0.35 0],...
'CameraTargetMode',get(0,'defaultaxesCameraTargetMode'),...
'CameraViewAngle',6.60861036031192,...
'CameraViewAngleMode',get(0,'defaultaxesCameraViewAngleMode'),...
'DataAspectRatio',[114.285714285714 1 2.85714285714286],...
'DataAspectRatioMode',get(0,'defaultaxesDataAspectRatioMode'),...
'PlotBoxAspectRatio',[1 0.442371013322668 0.442371013322668],...
'PlotBoxAspectRatioMode',get(0,'defaultaxesPlotBoxAspectRatioMode'),...
'XLim',[0 80],...
'XLimMode',get(0,'defaultaxesXLimMode'),...
'YLim',[0 0.7],...
'YLimMode',get(0,'defaultaxesYLimMode'),...
'ZLim',[-1 1],...
'ZLimMode',get(0,'defaultaxesZLimMode'),...
'XTick',[0 10 20 30 40 50 60 70 80],...
'XTickMode',get(0,'defaultaxesXTickMode'),...
'XTickLabel',{  '0'; '10'; '20'; '30'; '40'; '50'; '60'; '70'; '80' },...
'XTickLabelMode',get(0,'defaultaxesXTickLabelMode'),...
'YTick',[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7],...
'YTickMode',get(0,'defaultaxesYTickMode'),...
'YTickLabel',{  '0'; '0.1'; '0.2'; '0.3'; '0.4'; '0.5'; '0.6'; '0.7' },...
'YTickLabelMode',get(0,'defaultaxesYTickLabelMode'),...
'Color',get(0,'defaultaxesColor'),...
'CameraMode',get(0,'defaultaxesCameraMode'),...
'DataSpaceMode',get(0,'defaultaxesDataSpaceMode'),...
'ColorSpaceMode',get(0,'defaultaxesColorSpaceMode'),...
'DecorationContainerMode',get(0,'defaultaxesDecorationContainerMode'),...
'ChildContainerMode',get(0,'defaultaxesChildContainerMode'),...
'XGridHandleMode',get(0,'defaultaxesXGridHandleMode'),...
'YGridHandleMode',get(0,'defaultaxesYGridHandleMode'),...
'ZGridHandleMode',get(0,'defaultaxesZGridHandleMode'),...
'BoxFrameMode',get(0,'defaultaxesBoxFrameMode'),...
'XRulerMode',get(0,'defaultaxesXRulerMode'),...
'YRulerMode',get(0,'defaultaxesYRulerMode'),...
'ZRulerMode',get(0,'defaultaxesZRulerMode'),...
'AmbientLightSourceMode',get(0,'defaultaxesAmbientLightSourceMode'),...
'Box','on',...
'XGrid','on',...
'YGrid','on',...
'ZGrid','on',...
'Position',[0.50722891566265 0.616438356164384 0.456626506024096 0.280060882800609],...
'InnerPosition',[0.50722891566265 0.616438356164384 0.456626506024096 0.280060882800609],...
'ActivePositionProperty','position',...
'ActivePositionPropertyMode',get(0,'defaultaxesActivePositionPropertyMode'),...
'PositionConstraint','innerposition',...
'PositionConstraintMode',get(0,'defaultaxesPositionConstraintMode'),...
'LooseInset',[0.190636042402827 0.236950819672131 0.139310954063604 0.16155737704918],...
'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],...
'ColormapMode',get(0,'defaultaxesColormapMode'),...
'Alphamap',[0 0.0159 0.0317 0.0476 0.0635 0.0794 0.0952 0.1111 0.127 0.1429 0.1587 0.1746 0.1905 0.2063 0.2222 0.2381 0.254 0.2698 0.2857 0.3016 0.3175 0.3333 0.3492 0.3651 0.381 0.3968 0.4127 0.4286 0.4444 0.4603 0.4762 0.4921 0.5079 0.5238 0.5397 0.5556 0.5714 0.5873 0.6032 0.619 0.6349 0.6508 0.6667 0.6825 0.6984 0.7143 0.7302 0.746 0.7619 0.7778 0.7937 0.8095 0.8254 0.8413 0.8571 0.873 0.8889 0.9048 0.9206 0.9365 0.9524 0.9683 0.9841 1],...
'AlphamapMode',get(0,'defaultaxesAlphamapMode'),...
'ColorOrder',get(0,'defaultaxesColorOrder'),...
'FontSize',8,...
'SortMethod','childorder',...
'Tag','plotErrIter',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

h3 = get(h2,'title');

set(h3,...
'Parent',h2,...
'Units','data',...
'FontUnits','points',...
'DecorationContainer',[],...
'DecorationContainerMode','auto',...
'Color',[0 0 0],...
'ColorMode','auto',...
'Position',[40.0001229831599 0.704342419840858 0],...
'PositionMode','auto',...
'String',blanks(0),...
'Interpreter','tex',...
'Rotation',0,...
'RotationMode','auto',...
'FontName','Helvetica',...
'FontSize',10,...
'FontAngle','normal',...
'FontWeight','normal',...
'HorizontalAlignment','center',...
'HorizontalAlignmentMode','auto',...
'VerticalAlignment','bottom',...
'VerticalAlignmentMode','auto',...
'EdgeColor','none',...
'LineStyle','-',...
'LineWidth',0.5,...
'BackgroundColor','none',...
'Margin',2,...
'Clipping','off',...
'Layer','middle',...
'LayerMode','auto',...
'FontSmoothing','on',...
'FontSmoothingMode','auto',...
'DisplayName',blanks(0),...
'IncludeRenderer','on',...
'IsContainer','off',...
'IsContainerMode','auto',...
'DimensionNames',{  'X' 'Y' 'Z' },...
'DimensionNamesMode','auto',...
'XLimInclude','off',...
'XLimIncludeMode','auto',...
'YLimInclude','off',...
'YLimIncludeMode','auto',...
'ZLimInclude','off',...
'ZLimIncludeMode','auto',...
'CLimInclude','on',...
'ALimInclude','on',...
'Description','Axes Title',...
'DescriptionMode','auto',...
'Visible','on',...
'Serializable','on',...
'HandleVisibility','off',...
'HelpTopicKey',blanks(0),...
'ButtonDownFcn',blanks(0),...
'BusyAction','queue',...
'Interruptible','on',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} ,...
'DeleteFcn',blanks(0),...
'Tag',blanks(0),...
'HitTest','on',...
'PickableParts','visible',...
'PickablePartsMode','auto',...
'SeriesIndex','none',...
'SeriesIndexMode','auto');

h4 = get(h2,'xlabel');

set(h4,...
'Parent',h2,...
'Units','data',...
'FontUnits','points',...
'DecorationContainer',[],...
'DecorationContainerMode','auto',...
'Color',[0 0 0],...
'ColorMode','auto',...
'Position',[40.0000381469727 -0.0402977667493793 -1],...
'PositionMode','auto',...
'String','Number of iterations',...
'Interpreter','tex',...
'Rotation',0,...
'RotationMode','auto',...
'FontName','Helvetica',...
'FontSize',8,...
'FontAngle','normal',...
'FontWeight','normal',...
'HorizontalAlignment','center',...
'HorizontalAlignmentMode','auto',...
'VerticalAlignment','top',...
'VerticalAlignmentMode','auto',...
'EdgeColor','none',...
'LineStyle','-',...
'LineWidth',0.5,...
'BackgroundColor','none',...
'Margin',2,...
'Clipping','off',...
'Layer','back',...
'LayerMode','auto',...
'FontSmoothing','on',...
'FontSmoothingMode','auto',...
'DisplayName',blanks(0),...
'IncludeRenderer','on',...
'IsContainer','off',...
'IsContainerMode','auto',...
'DimensionNames',{  'X' 'Y' 'Z' },...
'DimensionNamesMode','auto',...
'XLimInclude','off',...
'XLimIncludeMode','auto',...
'YLimInclude','off',...
'YLimIncludeMode','auto',...
'ZLimInclude','off',...
'ZLimIncludeMode','auto',...
'CLimInclude','on',...
'ALimInclude','on',...
'Description','AxisRulerBase Label',...
'DescriptionMode','auto',...
'Visible','on',...
'Serializable','on',...
'HandleVisibility','off',...
'HelpTopicKey',blanks(0),...
'ButtonDownFcn',blanks(0),...
'BusyAction','queue',...
'Interruptible','on',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} ,...
'DeleteFcn',blanks(0),...
'Tag',blanks(0),...
'HitTest','on',...
'PickableParts','visible',...
'PickablePartsMode','auto',...
'SeriesIndex','none',...
'SeriesIndexMode','auto');

h5 = get(h2,'ylabel');

set(h5,...
'Parent',h2,...
'Units','data',...
'FontUnits','points',...
'DecorationContainer',[],...
'DecorationContainerMode','auto',...
'Color',[0 0 0],...
'ColorMode','auto',...
'Position',[-2.47639956092206 0.350000327825541 -1],...
'PositionMode','auto',...
'String','Error at each iteration',...
'Interpreter','tex',...
'Rotation',90,...
'RotationMode','auto',...
'FontName','Helvetica',...
'FontSize',8,...
'FontAngle','normal',...
'FontWeight','normal',...
'HorizontalAlignment','center',...
'HorizontalAlignmentMode','auto',...
'VerticalAlignment','bottom',...
'VerticalAlignmentMode','auto',...
'EdgeColor','none',...
'LineStyle','-',...
'LineWidth',0.5,...
'BackgroundColor','none',...
'Margin',2,...
'Clipping','off',...
'Layer','back',...
'LayerMode','auto',...
'FontSmoothing','on',...
'FontSmoothingMode','auto',...
'DisplayName',blanks(0),...
'IncludeRenderer','on',...
'IsContainer','off',...
'IsContainerMode','auto',...
'DimensionNames',{  'X' 'Y' 'Z' },...
'DimensionNamesMode','auto',...
'XLimInclude','off',...
'XLimIncludeMode','auto',...
'YLimInclude','off',...
'YLimIncludeMode','auto',...
'ZLimInclude','off',...
'ZLimIncludeMode','auto',...
'CLimInclude','on',...
'ALimInclude','on',...
'Description','AxisRulerBase Label',...
'DescriptionMode','auto',...
'Visible','on',...
'Serializable','on',...
'HandleVisibility','off',...
'HelpTopicKey',blanks(0),...
'ButtonDownFcn',blanks(0),...
'BusyAction','queue',...
'Interruptible','on',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} ,...
'DeleteFcn',blanks(0),...
'Tag',blanks(0),...
'HitTest','on',...
'PickableParts','visible',...
'PickablePartsMode','auto',...
'SeriesIndex','none',...
'SeriesIndexMode','auto');

h6 = get(h2,'zlabel');

set(h6,...
'Parent',h2,...
'Units','data',...
'FontUnits','points',...
'DecorationContainer',[],...
'DecorationContainerMode','auto',...
'Color',[0 0 0],...
'ColorMode','auto',...
'Position',[0 0 0],...
'PositionMode','auto',...
'String',blanks(0),...
'Interpreter','tex',...
'Rotation',0,...
'RotationMode','auto',...
'FontName','Helvetica',...
'FontSize',10,...
'FontAngle','normal',...
'FontWeight','normal',...
'HorizontalAlignment','right',...
'HorizontalAlignmentMode','auto',...
'VerticalAlignment','middle',...
'VerticalAlignmentMode','auto',...
'EdgeColor','none',...
'LineStyle','-',...
'LineWidth',0.5,...
'BackgroundColor','none',...
'Margin',2,...
'Clipping','off',...
'Layer','middle',...
'LayerMode','auto',...
'FontSmoothing','on',...
'FontSmoothingMode','auto',...
'DisplayName',blanks(0),...
'IncludeRenderer','on',...
'IsContainer','off',...
'IsContainerMode','auto',...
'DimensionNames',{  'X' 'Y' 'Z' },...
'DimensionNamesMode','auto',...
'XLimInclude','off',...
'XLimIncludeMode','auto',...
'YLimInclude','off',...
'YLimIncludeMode','auto',...
'ZLimInclude','off',...
'ZLimIncludeMode','auto',...
'CLimInclude','on',...
'ALimInclude','on',...
'Description','AxisRulerBase Label',...
'DescriptionMode','auto',...
'Visible','off',...
'Serializable','on',...
'HandleVisibility','off',...
'HelpTopicKey',blanks(0),...
'ButtonDownFcn',blanks(0),...
'BusyAction','queue',...
'Interruptible','on',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} ,...
'DeleteFcn',blanks(0),...
'Tag',blanks(0),...
'HitTest','on',...
'PickableParts','visible',...
'PickablePartsMode','auto',...
'SeriesIndex','none',...
'SeriesIndexMode','auto');

h7 = line(...
'Parent',h2,...
'Color',[0 0 1],...
'XData',[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75],...
'YData',[0.6238 0.1781 0.1129 0.086 0.0704 0.0582 0.0502 0.0449 0.0413 0.0385 0.0362 0.0338 0.0317 0.0304 0.0293 0.0283 0.0265 0.0241 0.0224 0.0212 0.0204 0.0196 0.0186 0.0176 0.0171 0.0165 0.0158 0.0153 0.015 0.0148 0.0146 0.0145 0.0143 0.0142 0.0142 0.0141 0.014 0.0139 0.0138 0.0137 0.0137 0.0136 0.0134 0.0132 0.013 0.0128 0.0125 0.0123 0.0122 0.0119 0.0118 0.0118 0.0118 0.0117 0.0117 0.0116 0.0116 0.0116 0.0116 0.0116 0.0115 0.0115 0.0115 0.0115 0.0115 0.0115 0.0115 0.0115 0.0115 0.0115 0.0115 0.0115 0.0115 0.0115 0.0115],...
'DimensionNames',{  'X' 'Y' 'Z' },...
'DimensionNamesMode',get(0,'defaultlineDimensionNamesMode'),...
'ButtonDownFcn',mat{2},...
'SeriesIndex','none',...
'SeriesIndexMode',get(0,'defaultlineSeriesIndexMode'),...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h8 = axes(...
'Parent',h1,...
'CameraPosition',[-0.0485500000000001 -0.0743999999999998 17.3205080756888],...
'CameraPositionMode',get(0,'defaultaxesCameraPositionMode'),...
'CameraTarget',[-0.0485500000000001 -0.0743999999999998 0],...
'CameraTargetMode',get(0,'defaultaxesCameraTargetMode'),...
'CameraViewAngle',6.60861036031192,...
'CameraViewAngleMode',get(0,'defaultaxesCameraViewAngleMode'),...
'DataAspectRatio',[3.26425 3.1875 1],...
'DataAspectRatioMode',get(0,'defaultaxesDataAspectRatioMode'),...
'PlotBoxAspectRatio',[1 0.566371695149906 0.566371695149906],...
'PlotBoxAspectRatioMode',get(0,'defaultaxesPlotBoxAspectRatioMode'),...
'XLim',[-3.3128 3.2157],...
'YLim',[-3.2619 3.1131],...
'ZLim',[-1 1],...
'ZLimMode',get(0,'defaultaxesZLimMode'),...
'XTick',[-3 -2 -1 0 1 2 3],...
'XTickMode',get(0,'defaultaxesXTickMode'),...
'XTickLabel',{  '-3'; '-2'; '-1'; '0'; '1'; '2'; '3' },...
'XTickLabelMode',get(0,'defaultaxesXTickLabelMode'),...
'YTick',[-3 -2 -1 0 1 2 3],...
'YTickMode',get(0,'defaultaxesYTickMode'),...
'YTickLabel',{  '-3'; '-2'; '-1'; '0'; '1'; '2'; '3' },...
'YTickLabelMode',get(0,'defaultaxesYTickLabelMode'),...
'Color',get(0,'defaultaxesColor'),...
'CameraMode',get(0,'defaultaxesCameraMode'),...
'DataSpaceMode',get(0,'defaultaxesDataSpaceMode'),...
'ColorSpaceMode',get(0,'defaultaxesColorSpaceMode'),...
'DecorationContainerMode',get(0,'defaultaxesDecorationContainerMode'),...
'ChildContainerMode',get(0,'defaultaxesChildContainerMode'),...
'XGridHandleMode',get(0,'defaultaxesXGridHandleMode'),...
'YGridHandleMode',get(0,'defaultaxesYGridHandleMode'),...
'ZGridHandleMode',get(0,'defaultaxesZGridHandleMode'),...
'BoxFrameMode',get(0,'defaultaxesBoxFrameMode'),...
'XRulerMode',get(0,'defaultaxesXRulerMode'),...
'YRulerMode',get(0,'defaultaxesYRulerMode'),...
'ZRulerMode',get(0,'defaultaxesZRulerMode'),...
'AmbientLightSourceMode',get(0,'defaultaxesAmbientLightSourceMode'),...
'Box','on',...
'XGrid','on',...
'YGrid','on',...
'ZGrid','on',...
'Position',[0.510843373493976 0.10806697108067 0.453012048192771 0.356164383561644],...
'InnerPosition',[0.510843373493976 0.10806697108067 0.453012048192771 0.356164383561644],...
'ActivePositionProperty','position',...
'ActivePositionPropertyMode',get(0,'defaultaxesActivePositionPropertyMode'),...
'PositionConstraint','innerposition',...
'PositionConstraintMode',get(0,'defaultaxesPositionConstraintMode'),...
'LooseInset',[0.191651865008881 0.203577464788732 0.140053285968028 0.138802816901408],...
'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],...
'ColormapMode',get(0,'defaultaxesColormapMode'),...
'Alphamap',[0 0.0159 0.0317 0.0476 0.0635 0.0794 0.0952 0.1111 0.127 0.1429 0.1587 0.1746 0.1905 0.2063 0.2222 0.2381 0.254 0.2698 0.2857 0.3016 0.3175 0.3333 0.3492 0.3651 0.381 0.3968 0.4127 0.4286 0.4444 0.4603 0.4762 0.4921 0.5079 0.5238 0.5397 0.5556 0.5714 0.5873 0.6032 0.619 0.6349 0.6508 0.6667 0.6825 0.6984 0.7143 0.7302 0.746 0.7619 0.7778 0.7937 0.8095 0.8254 0.8413 0.8571 0.873 0.8889 0.9048 0.9206 0.9365 0.9524 0.9683 0.9841 1],...
'AlphamapMode',get(0,'defaultaxesAlphamapMode'),...
'ColorOrder',get(0,'defaultaxesColorOrder'),...
'FontSize',8,...
'SortMethod','childorder',...
'Tag','plotStepFcn',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

h9 = get(h8,'title');

set(h9,...
'Parent',h8,...
'Units','data',...
'FontUnits','points',...
'DecorationContainer',[],...
'DecorationContainerMode','auto',...
'Color',[0 0 0],...
'ColorMode','auto',...
'Position',[-0.0485398717137642 3.14422798156738 0],...
'PositionMode','auto',...
'String',blanks(0),...
'Interpreter','tex',...
'Rotation',0,...
'RotationMode','auto',...
'FontName','Helvetica',...
'FontSize',10,...
'FontAngle','normal',...
'FontWeight','normal',...
'HorizontalAlignment','center',...
'HorizontalAlignmentMode','auto',...
'VerticalAlignment','bottom',...
'VerticalAlignmentMode','auto',...
'EdgeColor','none',...
'LineStyle','-',...
'LineWidth',0.5,...
'BackgroundColor','none',...
'Margin',2,...
'Clipping','off',...
'Layer','middle',...
'LayerMode','auto',...
'FontSmoothing','on',...
'FontSmoothingMode','auto',...
'DisplayName',blanks(0),...
'IncludeRenderer','on',...
'IsContainer','off',...
'IsContainerMode','auto',...
'DimensionNames',{  'X' 'Y' 'Z' },...
'DimensionNamesMode','auto',...
'XLimInclude','off',...
'XLimIncludeMode','auto',...
'YLimInclude','off',...
'YLimIncludeMode','auto',...
'ZLimInclude','off',...
'ZLimIncludeMode','auto',...
'CLimInclude','on',...
'ALimInclude','on',...
'Description','Axes Title',...
'DescriptionMode','auto',...
'Visible','on',...
'Serializable','on',...
'HandleVisibility','off',...
'HelpTopicKey',blanks(0),...
'ButtonDownFcn',blanks(0),...
'BusyAction','queue',...
'Interruptible','on',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} ,...
'DeleteFcn',blanks(0),...
'Tag',blanks(0),...
'HitTest','on',...
'PickableParts','visible',...
'PickablePartsMode','auto',...
'SeriesIndex','none',...
'SeriesIndexMode','auto');

h10 = get(h8,'xlabel');

set(h10,...
'Parent',h8,...
'Units','data',...
'FontUnits','points',...
'DecorationContainer',[],...
'DecorationContainerMode','auto',...
'Color',[0 0 0],...
'ColorMode','auto',...
'Position',[-0.0485468966961644 -3.55076713562012 -1],...
'PositionMode','auto',...
'String','Partitions (theoretical bounds are -inf to +inf)',...
'Interpreter','tex',...
'Rotation',0,...
'RotationMode','auto',...
'FontName','Helvetica',...
'FontSize',8,...
'FontAngle','normal',...
'FontWeight','normal',...
'HorizontalAlignment','center',...
'HorizontalAlignmentMode','auto',...
'VerticalAlignment','top',...
'VerticalAlignmentMode','auto',...
'EdgeColor','none',...
'LineStyle','-',...
'LineWidth',0.5,...
'BackgroundColor','none',...
'Margin',2,...
'Clipping','off',...
'Layer','back',...
'LayerMode','auto',...
'FontSmoothing','on',...
'FontSmoothingMode','auto',...
'DisplayName',blanks(0),...
'IncludeRenderer','on',...
'IsContainer','off',...
'IsContainerMode','auto',...
'DimensionNames',{  'X' 'Y' 'Z' },...
'DimensionNamesMode','auto',...
'XLimInclude','off',...
'XLimIncludeMode','auto',...
'YLimInclude','off',...
'YLimIncludeMode','auto',...
'ZLimInclude','off',...
'ZLimIncludeMode','auto',...
'CLimInclude','on',...
'ALimInclude','on',...
'Description','AxisRulerBase Label',...
'DescriptionMode','auto',...
'Visible','on',...
'Serializable','on',...
'HandleVisibility','off',...
'HelpTopicKey',blanks(0),...
'ButtonDownFcn',blanks(0),...
'BusyAction','queue',...
'Interruptible','on',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} ,...
'DeleteFcn',blanks(0),...
'Tag',blanks(0),...
'HitTest','on',...
'PickableParts','visible',...
'PickablePartsMode','auto',...
'SeriesIndex','none',...
'SeriesIndexMode','auto');

h11 = get(h8,'ylabel');

set(h11,...
'Parent',h8,...
'Units','data',...
'FontUnits','points',...
'DecorationContainer',[],...
'DecorationContainerMode','auto',...
'Color',[0 0 0],...
'ColorMode','auto',...
'Position',[-3.46590192172295 -0.0743969082832328 -1],...
'PositionMode','auto',...
'String','Codewords',...
'Interpreter','tex',...
'Rotation',90,...
'RotationMode','auto',...
'FontName','Helvetica',...
'FontSize',8,...
'FontAngle','normal',...
'FontWeight','normal',...
'HorizontalAlignment','center',...
'HorizontalAlignmentMode','auto',...
'VerticalAlignment','bottom',...
'VerticalAlignmentMode','auto',...
'EdgeColor','none',...
'LineStyle','-',...
'LineWidth',0.5,...
'BackgroundColor','none',...
'Margin',2,...
'Clipping','off',...
'Layer','back',...
'LayerMode','auto',...
'FontSmoothing','on',...
'FontSmoothingMode','auto',...
'DisplayName',blanks(0),...
'IncludeRenderer','on',...
'IsContainer','off',...
'IsContainerMode','auto',...
'DimensionNames',{  'X' 'Y' 'Z' },...
'DimensionNamesMode','auto',...
'XLimInclude','off',...
'XLimIncludeMode','auto',...
'YLimInclude','off',...
'YLimIncludeMode','auto',...
'ZLimInclude','off',...
'ZLimIncludeMode','auto',...
'CLimInclude','on',...
'ALimInclude','on',...
'Description','AxisRulerBase Label',...
'DescriptionMode','auto',...
'Visible','on',...
'Serializable','on',...
'HandleVisibility','off',...
'HelpTopicKey',blanks(0),...
'ButtonDownFcn',blanks(0),...
'BusyAction','queue',...
'Interruptible','on',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} ,...
'DeleteFcn',blanks(0),...
'Tag',blanks(0),...
'HitTest','on',...
'PickableParts','visible',...
'PickablePartsMode','auto',...
'SeriesIndex','none',...
'SeriesIndexMode','auto');

h12 = get(h8,'zlabel');

set(h12,...
'Parent',h8,...
'Units','data',...
'FontUnits','points',...
'DecorationContainer',[],...
'DecorationContainerMode','auto',...
'Color',[0 0 0],...
'ColorMode','auto',...
'Position',[0 0 0],...
'PositionMode','auto',...
'String',blanks(0),...
'Interpreter','tex',...
'Rotation',0,...
'RotationMode','auto',...
'FontName','Helvetica',...
'FontSize',10,...
'FontAngle','normal',...
'FontWeight','normal',...
'HorizontalAlignment','right',...
'HorizontalAlignmentMode','auto',...
'VerticalAlignment','middle',...
'VerticalAlignmentMode','auto',...
'EdgeColor','none',...
'LineStyle','-',...
'LineWidth',0.5,...
'BackgroundColor','none',...
'Margin',2,...
'Clipping','off',...
'Layer','middle',...
'LayerMode','auto',...
'FontSmoothing','on',...
'FontSmoothingMode','auto',...
'DisplayName',blanks(0),...
'IncludeRenderer','on',...
'IsContainer','off',...
'IsContainerMode','auto',...
'DimensionNames',{  'X' 'Y' 'Z' },...
'DimensionNamesMode','auto',...
'XLimInclude','off',...
'XLimIncludeMode','auto',...
'YLimInclude','off',...
'YLimIncludeMode','auto',...
'ZLimInclude','off',...
'ZLimIncludeMode','auto',...
'CLimInclude','on',...
'ALimInclude','on',...
'Description','AxisRulerBase Label',...
'DescriptionMode','auto',...
'Visible','off',...
'Serializable','on',...
'HandleVisibility','off',...
'HelpTopicKey',blanks(0),...
'ButtonDownFcn',blanks(0),...
'BusyAction','queue',...
'Interruptible','on',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} ,...
'DeleteFcn',blanks(0),...
'Tag',blanks(0),...
'HitTest','on',...
'PickableParts','visible',...
'PickablePartsMode','auto',...
'SeriesIndex','none',...
'SeriesIndexMode','auto');

h13 = line(...
'Parent',h8,...
'Color',[0 0 1],...
'XData',[-3.3128 -2.68 -2.68 -2.0471 -2.0471 -1.4143 -1.4143 -1.003 -1.003 -0.6559 -0.6559 -0.3325 -0.3325 -0.0396 -0.0396 0.1957 0.1957 0.3966 0.3966 0.5941 0.5941 0.8206 0.8206 1.0799 1.0799 1.385 1.385 1.7551 1.7551 2.242 2.242 2.242 2.242 2.7289 2.7289 3.2157 3.2157],...
'YData',[-2.452 -2.452 -2.452 -2.452 -1.6422 -1.6422 -1.1864 -1.1864 -0.8196 -0.8196 -0.4923 -0.4923 -0.1728 -0.1728 0.0936 0.0936 0.2977 0.2977 0.4954 0.4954 0.6928 0.6928 0.9485 0.9485 1.2114 1.2114 1.5586 1.5586 1.9516 1.9516 2.5323 2.5323 2.5323 2.5323 2.5323 2.5323 2.5323],...
'DimensionNames',{  'X' 'Y' 'Z' },...
'DimensionNamesMode',get(0,'defaultlineDimensionNamesMode'),...
'ButtonDownFcn',mat{3},...
'SeriesIndex','none',...
'SeriesIndexMode',get(0,'defaultlineSeriesIndexMode'),...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h14 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'ListboxTop',0,...
'String',{  blanks(0) },...
'Style','frame',...
'Position',[0.0265060240963855 0.0471841704718417 0.26144578313253 0.264840182648402],...
'Children',[],...
'Tag','frame13',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h15 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','randn(10000,1)',...
'Style','edit',...
'Position',[0.127710843373494 0.942161339421613 0.292771084337349 0.0334855403348554],...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)sqdtool('editTS_Callback',hObject,eventdata,guidata(hObject)),...
'Children',[],...
'Tag','editTS',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h16 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'ListboxTop',0,...
'String','Training Set:',...
'Style','text',...
'Position',[0.0216867469879518 0.939117199391172 0.0891566265060241 0.0334855403348554],...
'Children',[],...
'Tag','textTS',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h17 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'ListboxTop',0,...
'String','Total number of iterations =',...
'Style','text',...
'Position',[0.76004016064257 0.967468175388968 0.187751004016064 0.0226308345120226],...
'Children',[],...
'Tag','text63',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h18 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','75',...
'Style','text',...
'Position',[0.950602409638554 0.968036529680366 0.0481927710843373 0.0228310502283106],...
'Children',[],...
'Enable','inactive',...
'Tag','editTotalIter',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h19 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'ListboxTop',0,...
'String',{  blanks(0) },...
'Style','frame',...
'Position',[0.0265060240963855 0.480974124809741 0.397590361445783 0.165905631659056],...
'Children',[],...
'Tag','frame14',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h20 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','Stopping criteria:',...
'Style','text',...
'Position',[0.03714859437751 0.591230551626591 0.113453815261044 0.0282885431400283],...
'Children',[],...
'Tag','text65',...
'UserData',[],...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h21 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String',{  'Relative threshold'; 'Maximum iteration'; 'Whichever comes first' },...
'Style','popupmenu',...
'Value',1,...
'Position',[0.193975903614458 0.581430745814307 0.216867469879518 0.0334855403348554],...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)sqdtool('popupStopCri_Callback',hObject,eventdata,guidata(hObject)),...
'Children',[],...
'Tag','popupStopCri',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h22 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','Relative threshold:',...
'Style','text',...
'Position',[0.03714859437751 0.541725601131542 0.122489959839357 0.0297029702970297],...
'Children',[],...
'Tag','textRelTh',...
'UserData',[],...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h23 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','Maximum iteration:',...
'Style','text',...
'Position',[0.03714859437751 0.499292786421499 0.129518072289157 0.0226308345120227],...
'Children',[],...
'Enable','off',...
'Tag','textMaxIter',...
'UserData',[],...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h24 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','1e-7',...
'Style','edit',...
'Position',[0.193975903614458 0.538812785388128 0.216867469879518 0.0334855403348554],...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)sqdtool('editRelTh_Callback',hObject,eventdata,guidata(hObject)),...
'Children',[],...
'Tag','editRelTh',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h25 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','1000',...
'Style','edit',...
'Position',[0.193975903614458 0.494672754946728 0.216867469879518 0.0334855403348555],...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)sqdtool('editMaxIter_Callback',hObject,eventdata,guidata(hObject)),...
'Children',[],...
'Tag','editMaxIter',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h26 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'ListboxTop',0,...
'String','Stopping criteria',...
'Style','text',...
'Position',[0.0542168674698795 0.628614916286149 0.112048192771084 0.0289193302891934],...
'Children',[],...
'Tag','text68',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h27 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'ListboxTop',0,...
'String',{  blanks(0) },...
'Style','frame',...
'Position',[0.0265060240963855 0.671232876712329 0.397590361445783 0.243531202435312],...
'Children',[],...
'Tag','frame15',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h28 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','Source of initial codebook:',...
'Style','text',...
'Position',[0.0373493975903614 0.863013698630137 0.174698795180723 0.0228310502283106],...
'Children',[],...
'Tag','textSQSource',...
'UserData',[],...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h29 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String',{  'Auto-generate'; 'User defined' },...
'Style','popupmenu',...
'Value',1,...
'Position',[0.26144578313253 0.852359208523592 0.153012048192771 0.0334855403348554],...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)sqdtool('popupSQSource_Callback',hObject,eventdata,guidata(hObject)),...
'Children',[],...
'Tag','popupSQSource',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h30 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','Number of levels:',...
'Style','text',...
'Position',[0.0373493975903614 0.818873668188737 0.174698795180723 0.0243531202435312],...
'Children',[],...
'Tag','textNumLevel',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h31 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','15',...
'Style','edit',...
'Position',[0.26144578313253 0.812785388127854 0.153012048192771 0.0334855403348554],...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)sqdtool('editNumLevel_Callback',hObject,eventdata,guidata(hObject)),...
'Children',[],...
'Tag','editNumLevel',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h32 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','Initial codebook:',...
'Style','text',...
'Position',[0.0373493975903614 0.777777777777778 0.174698795180723 0.0228310502283106],...
'Children',[],...
'Enable','off',...
'Tag','textInitCB',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h33 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','[-1.0 : 0.15 : 1.1]',...
'Style','edit',...
'Position',[0.26144578313253 0.768645357686454 0.153012048192771 0.0334855403348554],...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)sqdtool('editInitCB_Callback',hObject,eventdata,guidata(hObject)),...
'Children',[],...
'Tag','editInitCB',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h34 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','Source of initial boundary points:',...
'Style','text',...
'Position',[0.03714859437751 0.72984441301273 0.220883534136546 0.0268741159830269],...
'Children',[],...
'Enable','off',...
'Tag','textInitPTSource',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h35 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','[-0.9 : 0.15 : 1.1]',...
'Style','edit',...
'Position',[0.28144578313253 0.681887366818874 0.133012048192771 0.0334855403348554],...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)sqdtool('editInitPT_Callback',hObject,eventdata,guidata(hObject)),...
'Children',[],...
'Tag','editInitPT',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h36 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String',{  'Mid-points'; 'User defined' },...
'Style','popupmenu',...
'Value',1,...
'Position',[0.26144578313253 0.724505327245053 0.153012048192771 0.0334855403348554],...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)sqdtool('popupInitPTSource_Callback',hObject,eventdata,guidata(hObject)),...
'Children',[],...
'Enable','off',...
'Tag','popupInitPTSource',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h37 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','Initial boundary points (unbounded):',...
'Style','text',...
'Position',[0.03714859437751 0.691654879773692 0.241967871485944 0.0240452616690241],...
'Children',[],...
'Enable','off',...
'Tag','textInitPT',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h38 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'ListboxTop',0,...
'String','Scalar quantizer',...
'Style','text',...
'Position',[0.0578313253012048 0.899543378995434 0.107228915662651 0.0258751902587518],...
'Children',[],...
'Tag','text74',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h39 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'ListboxTop',0,...
'String',{  blanks(0) },...
'Style','frame',...
'Position',[0.0265060240963855 0.340943683409437 0.397590361445783 0.10958904109589],...
'Children',[],...
'Tag','frame16',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h40 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','Searching methods:',...
'Style','text',...
'Position',[0.0373493975903614 0.397260273972603 0.139759036144578 0.0258751902587519],...
'Children',[],...
'Tag','text75',...
'UserData',[],...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h41 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String',{  'Linear search'; 'Binary search' },...
'Style','popupmenu',...
'Value',1,...
'Position',[0.193975903614458 0.392694063926941 0.216867469879518 0.0334855403348554],...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)sqdtool('popupSearchMeth_Callback',hObject,eventdata,guidata(hObject)),...
'Children',[],...
'Tag','popupSearchMeth',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h42 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'ListboxTop',0,...
'String','Algorithmic details',...
'Style','text',...
'Position',[0.0578313253012048 0.439878234398782 0.121686746987952 0.0228310502283105],...
'Children',[],...
'Tag','text76',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h43 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','Tie-breaking rules:',...
'Style','text',...
'Position',[0.0373493975903614 0.360730593607306 0.132530120481928 0.0243531202435312],...
'Children',[],...
'Tag','text77',...
'UserData',[],...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h44 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String',{  'Lower indexed codeword'; 'Higher indexed codeword' },...
'Style','popupmenu',...
'Value',1,...
'Position',[0.193975903614458 0.351598173515982 0.216867469879518 0.0334855403348554],...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)sqdtool('popupTieBreakRule_Callback',hObject,eventdata,guidata(hObject)),...
'Children',[],...
'Tag','popupTieBreakRule',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h45 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','Performance curve (mean square error at each iteration)',...
'Style','text',...
'Position',[0.479438314944835 0.929478138222849 0.473420260782347 0.0253878702397743],...
'Children',[],...
'Tag','text78',...
'FontWeight','bold',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h46 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','Staircase character of the quantizer',...
'Style','text',...
'Position',[0.479518072289157 0.493150684931507 0.271084337349398 0.0228310502283106],...
'Children',[],...
'Tag','text79',...
'FontWeight','bold',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h47 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String',blanks(0),...
'Style','edit',...
'Position',[0 0.0015220700152207 0.996385542168674 0.0350076103500761],...
'Children',[],...
'Tag','editStatus',...
'UserData',[],...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h48 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'ListboxTop',0,...
'String','Design and Plot',...
'Position',[0.3 0.191780821917808 0.120481927710843 0.0365296803652968],...
'Callback',@(hObject,eventdata)sqdtool('pushbutnPlotFig_Callback',hObject,eventdata,guidata(hObject)),...
'Children',[],...
'BusyAction','cancel',...
'Tag','pushbutnPlotFig',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h49 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','Status: Ready',...
'Style','text',...
'Position',[0.00843373493975903 0.0076103500761035 0.98433734939759 0.0228310502283105],...
'Children',[],...
'Tag','textStatus',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h50 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'ListboxTop',0,...
'String','Generate Model',...
'Position',[0.172289156626506 0.0532724505327245 0.108433734939759 0.0350076103500761],...
'Callback',@(hObject,eventdata)sqdtool('pushbutnRealzMdl_Callback',hObject,eventdata,guidata(hObject)),...
'Children',[],...
'BusyAction','cancel',...
'Tag','pushbutnRealzMdl',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h51 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String',{  'Current model'; 'New model' },...
'Style','popupmenu',...
'Value',1,...
'Position',[0.157831325301205 0.258751902587519 0.119277108433735 0.0334855403348554],...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)sqdtool('popupDestMdl_Callback',hObject,eventdata,guidata(hObject)),...
'Children',[],...
'Tag','popupDestMdl',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h52 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','Destination:',...
'Style','text',...
'Position',[0.036144578313253 0.26179604261796 0.0939759036144578 0.0289193302891933],...
'Children',[],...
'Tag','text82',...
'UserData',[],...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h53 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'ListboxTop',0,...
'String','Overwrite target block(s)',...
'Style','checkbox',...
'Position',[0.036144578313253 0.0989345509893455 0.187951807228916 0.0319634703196347],...
'Callback',@(hObject,eventdata)sqdtool('chkboxOverwriteBlock_Callback',hObject,eventdata,guidata(hObject)),...
'Children',[],...
'Tag','chkboxOverwriteBlock',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h54 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'ListboxTop',0,...
'String','Export Outputs',...
'Position',[0.301204819277108 0.120243531202435 0.120481927710843 0.0365296803652968],...
'Callback',@(hObject,eventdata)sqdtool('pushbutnExport_Callback',hObject,eventdata,guidata(hObject)),...
'Children',[],...
'BusyAction','cancel',...
'Tag','pushbutnExport',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h55 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'String',{  'Frame' },...
'Style','frame',...
'Position',[0.434939759036144 0.045662100456621 0.00120481927710842 0.951293759512938],...
'Children',[],...
'Tag','frame17',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h56 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'ListboxTop',0,...
'String','Model',...
'Style','text',...
'Position',[0.0518072289156626 0.302891933028919 0.0506024096385542 0.0243531202435312],...
'Children',[],...
'Tag','text81',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h57 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','Decoder block name:',...
'Style','text',...
'Position',[0.036144578313253 0.144596651445967 0.143373493975904 0.0228310502283105],...
'Children',[],...
'Tag','textDecBlkName',...
'UserData',[],...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h58 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','SQ Decoder',...
'Style','edit',...
'Position',[0.191566265060241 0.140030441400304 0.0843373493975904 0.0289193302891933],...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)sqdtool('editDecBlkName_Callback',hObject,eventdata,guidata(hObject)),...
'Children',[],...
'Tag','editDecBlkName',...
'UserData',[],...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h59 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','Encoder block name:',...
'Style','text',...
'Position',[0.036144578313253 0.181126331811263 0.14578313253012 0.0289193302891933],...
'Children',[],...
'Tag','textEncBlkName',...
'UserData',[],...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h60 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','SQ Encoder',...
'Style','edit',...
'Position',[0.191566265060241 0.182648401826484 0.0843373493975904 0.0289193302891933],...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)sqdtool('editEncBlkName_Callback',hObject,eventdata,guidata(hObject)),...
'Children',[],...
'Tag','editEncBlkName',...
'UserData',[],...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h61 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String','Block type:',...
'Style','text',...
'Position',[0.0349397590361446 0.226788432267884 0.0891566265060241 0.0228310502283105],...
'Children',[],...
'Tag','textBlockType',...
'UserData',[],...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

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

h62 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'String',{  'Encoder'; 'Decoder'; 'Both' },...
'Style','popupmenu',...
'Value',1,...
'Position',[0.157831325301205 0.219178082191781 0.119277108433735 0.0334855403348554],...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)sqdtool('popupBlockType_Callback',hObject,eventdata,guidata(hObject)),...
'Children',[],...
'Tag','popupBlockType',...
'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(message('MATLAB:guide:StateFieldNotFound', 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
    % SQDTOOL_EXPORT
    % create the GUI only if we are not in the process of loading it
    % already
    gui_Create = true;
elseif local_isInvokeActiveXCallback(gui_State, varargin{:})
    % SQDTOOL_EXPORT(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_isInvokeHGCallback(gui_State, varargin{:})
    % SQDTOOL_EXPORT('CALLBACK',hObject,eventData,handles,...)
    gui_Create = false;
else
    % SQDTOOL_EXPORT(...)
    % 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) && ~ishghandle(fig,'figure')
            fig = get(fig,'parent');
        end
        
        designEval = isappdata(0,'CreatingGUIDEFigure') || (isscalar(fig)&&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 && ishghandle(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 MATLAB code 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) && ishghandle(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) && ishghandle(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 = matlab.hg.internal.openfigLegacy(name, singleton);
    set(0,'defaultFigureVisible',gui_OldDefaultVisible);
else
    % Call version of openfig that accepts 'auto' option"
    gui_hFigure = matlab.hg.internal.openfigLegacy(name, singleton, visible);  
%     %workaround for CreateFcn not called to create ActiveX
%         peers=findobj(findall(allchild(gui_hFigure)),'type','uicontrol','style','text');    
%         for i=1:length(peers)
%             if isappdata(peers(i),'Control')
%                 actxproxy(peers(i));
%             end            
%         end
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_isInvokeHGCallback(gui_State, varargin)

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