function bfitcheckshownormresiduals(checkon,datahandle)
% BFITCHECKSHOWNORMRESIDUALS Show norm of residuals as text on figure.

%   Copyright 1984-2000 The MathWorks, Inc.
%   $Revision: 1.10 $  $Date: 2000/08/31 20:54:29 $

residinfo = getappdata(datahandle,'_Basic_Fit_Resid_Info');
residfigure = findobj(0,'Basic_Fit_Fig_Tag',residinfo.figuretag);
fitsshowing = find(getappdata(datahandle,'_Basic_Fit_Showing'));

residnrmTxtH = getappdata(datahandle,'_Basic_Fit_ResidTxt_Handle');

if checkon
    residnrmTxtH = bfitcreatenormresidtxt(residinfo.axes,residfigure,datahandle,fitsshowing);
    if ~isempty(residnrmTxtH)
        appdata.type = 'residnrmtxt';
        appdata.index = [];
        setappdata(residnrmTxtH,'_bfit',appdata);
    end
else % delete
    if ~isempty(residinfo.axes) % The axes could have been deleted already
        delete(residnrmTxtH)
    end
    residnrmTxtH = [];
end
setappdata(datahandle,'_Basic_Fit_ResidTxt_Handle', residnrmTxtH); % norm of residuals txt

guistate = getappdata(datahandle,'_Basic_Fit_Gui_State');
guistate.showresid = checkon;
setappdata(datahandle,'_Basic_Fit_Gui_State', guistate);

