Home > core > dispEM.m

dispEM

PURPOSE ^

dispEM

SYNOPSIS ^

function dispEM(string,throwErrors,toList,trimWarnings)

DESCRIPTION ^

 dispEM
   Helper function to print warning/errors

   string          the warning/error to show. "WARNING: " is appended automatically
                   if a warning
   throwErrors     true if the function should throw an error (optional, default true)
   toList          a cell array of items to list. If supplied, then the
                   string will be printed followed by each element in
                   toList. If it is supplied but empty then nothing is
                   printed (optional, default {})
   trimWarnings    true if only a maximal of 10 items should be displayed in
                   a given error/warning (optional, default true)

 Usage: dispEM(string,throwErrors,toList,trimWarnings)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function dispEM(string,throwErrors,toList,trimWarnings)
0002 % dispEM
0003 %   Helper function to print warning/errors
0004 %
0005 %   string          the warning/error to show. "WARNING: " is appended automatically
0006 %                   if a warning
0007 %   throwErrors     true if the function should throw an error (optional, default true)
0008 %   toList          a cell array of items to list. If supplied, then the
0009 %                   string will be printed followed by each element in
0010 %                   toList. If it is supplied but empty then nothing is
0011 %                   printed (optional, default {})
0012 %   trimWarnings    true if only a maximal of 10 items should be displayed in
0013 %                   a given error/warning (optional, default true)
0014 %
0015 % Usage: dispEM(string,throwErrors,toList,trimWarnings)
0016 
0017 if nargin<2
0018     throwErrors=true;
0019 end
0020 if nargin<3
0021     toList=[];
0022 elseif isempty(toList)
0023     return;
0024 else
0025     toList=convertCharArray(toList);
0026 end
0027 if nargin<4
0028     trimWarnings=true;
0029 end
0030 if numel(toList)>10 && trimWarnings==true
0031     toList{10}=['...and ' num2str(numel(toList)-9) ' more'];
0032     toList(11:end)=[];
0033 end
0034 if throwErrors==false
0035     errorText=['WARNING: ' string '\n'];
0036     % Wrap text to command window size
0037     sz = get(0, 'CommandWindowSize');
0038     errorText = textwrap({errorText},sz(1));
0039     errorText = strjoin(errorText,'\n');
0040 else
0041     errorText=[string '\n'];
0042 end
0043 if ~isempty(toList)
0044     for i=1:numel(toList)
0045         errorText=[errorText '\t' toList{i} '\n'];
0046     end
0047 end
0048 if throwErrors==false
0049     %Escape special characters, required for fprintf
0050     errorText=regexprep(errorText,'(\\|\%|'')(\\n)$','\\$0');
0051     fprintf([errorText '\n']);
0052 else
0053     throw(MException('',errorText));
0054 end
0055 end

Generated by m2html © 2005