This is a static copy of a profile report

Home

saveas (Calls: 12, Time: 11.201 s)
Generated 16-Jul-2020 17:08:36 using performance time.
function in file /Applications/MATLAB_R2020a.app/toolbox/matlab/general/saveas.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
OC3function2
hhsave_VFI_3OCfunction10
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
181
print( h, name, ['-d' dev{i}] ...
1210.916 s97.5%
159
[ops,dev,ext] = printtables(pr...
120.161 s1.4%
152
if ~isempty(format) &&...
120.104 s0.9%
160
i = strmatch( format, ext ); %...
120.006 s0.1%
115
[fp,fn,fe]=fileparts(name);
120.005 s0.0%
All other lines  0.008 s0.1%
Totals  11.201 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
printfunction1210.915 s97.4%
printjobfunction120.132 s1.2%
printtablesfunction120.027 s0.2%
strmatchfunction120.005 s0.0%
filepartsfunction120.004 s0.0%
isCharOrStringfunction120.001 s0.0%
general/private/isfigurefunction120.001 s0.0%
Self time (built-ins, overhead, etc.)  0.117 s1.0%
Totals  11.201 s100% 
Code Analyzer results
Line numberMessage
167STRMATCH is not recommended. Use STRCMP instead.
Coverage results
Show coverage for parent directory
Total lines in function185
Non-code lines (comments, blank lines)100
Code lines (lines that can run)85
Code lines that did run42
Code lines that did not run43
Coverage (did run/can run)49.41 %
Function listing
time 
Calls 
 line
   1 
function saveas( h, name, format )
   2 
%SAVEAS Save Figure or Simulink block diagram in desired output format
   3 
%   SAVEAS(H,'FILENAME')
   4 
%   Will save the Figure or Simulink block diagram with handle H to file 
   5 
%   called FILENAME. 
   6 
%   The format of the file is determined from the extension of FILENAME.
   7 
%
   8 
%   SAVEAS(H,'FILENAME','FORMAT')
   9 
%   Will save the Figure or Simulink block diagram  with handle H to file 
  10 
%   called FILENAME in the format specified by FORMAT. FORMAT can be the 
  11 
%   same values as extensions of FILENAME. 
  12 
%   The FILENAME extension does not have to be the same as FORMAT.  
  13 
%   The specified FORMAT overrides FILENAME extension.
  14 
%
  15 
%   Valid options for FORMAT are:
  16 
%
  17 
%   'fig'  - save figure to a single binary FIG-file.  Reload using OPEN. 
  18 
%   'm'    - save figure to binary FIG-file, and produce callable
  19 
%            MATLAB code file for reload.
  20 
%   'mfig' - same as M.
  21 
%   'mmat' - save figure to callable MATLAB code file as series of creation
  22 
%            commands with param-value pair arguments.  Large data is saved
  23 
%            to MAT-file.  
  24 
%            Note: MMAT Does not support some newer graphics features. Use
  25 
%                  this format only when code inspection is the primary goal.
  26 
%                  FIG-files support all features, and load more quickly. 
  27 
%
  28 
%   Additional FORMAT options include devices allowed by PRINT.
  29 
%
  30 
%   NOTE: not all format options are allowed for Simulink block diagrams.
  31 
%   See the online help for more information.
  32 
%
  33 
%   Examples:
  34 
%
  35 
%   Write current figure to MATLAB fig file
  36 
%
  37 
%       saveas(gcf, 'output', 'fig')
  38 
%
  39 
%   Write current figure to windows bitmap file
  40 
%
  41 
%       saveas(gcf, 'output', 'bmp')
  42 
%
  43 
%   Write block diagram named 'demo' to an Encapsulated Postscript file
  44 
%
  45 
%       saveas(get_param('demo', 'Handle'), 'output', 'eps')
  46 
%
  47 
%   In the following list, SAVE_SYSTEM is available for Simulink users only. 
  48 
%   See also LOAD, SAVE, OPEN, PRINT, SAVE_SYSTEM, EXPORTGRAPHICS.
  49 

  50 
%   Copyright 1984-2019 The MathWorks, Inc.
  51 

  52 
import matlab.graphics.internal.isCharOrString;
  53 

  54 
%Input validation
< 0.001 
     12 
  55
if nargin < 2  
  56 
    error(message('MATLAB:saveas:tooFewInputs'))
< 0.001 
     12 
  57
end 
  58 

< 0.001 
     12 
  59
if ~all(ishandle(h)) 
  60 
    error('MATLAB:saveas:invalidHandle','%s',...
  61 
        getString(message('MATLAB:saveas:invalidHandle')))
< 0.001 
     12 
  62
end 
  63 

< 0.001 
     12 
  64
if all(ishghandle(h)) 
  65 
    
  0.001 
     12 
  66
    notfig = find(~isfigure(h));  
< 0.001 
     12 
  67
    if ~isempty(notfig) 
  68 
        for n = notfig
  69 
            hP = ancestor(h(n), 'figure');
  70 
            if isempty(hP)
  71 
                % At least one of the objects has no figure parent.  Don't save
  72 
                % any of them
  73 
                h = [];
  74 
                break;
  75 
            else
  76 
                % Update non-figure with the parent figure
  77 
                h(n) = hP;
  78 
            end
  79 
        end
< 0.001 
     12 
  80
    end 
  81 
  
< 0.001 
     12 
  82
    if isempty(h) 
  83 
        error('MATLAB:saveas:invalidHandle','%s',...
  84 
           getString(message('MATLAB:saveas:invalidFigureHandle')))
< 0.001 
     12 
  85
    end 
  86 
    
  87 
else
  88 
    if ~strcmp( 'block_diagram', get_param( h, 'type' ) ) ...
  89 
            && ~strcmp( 'SubSystem', get_param( h, 'blocktype' ) )
  90 
        error('MATLAB:saveas:invalidHandle','%s',...
  91 
            getString(message('MATLAB:saveas:invalidSimulinkHandle')))
  92 
    end
< 0.001 
     12 
  93
end 
  94 

  0.001 
     12 
  95
if ~isCharOrString(name) || isempty(name) 
  96 
    error('MATLAB:saveas:invalidFilename','%s',...
  97 
    getString(message('MATLAB:saveas:invalidFilename')));
< 0.001 
     12 
  98
end 
  99 

 100 
%converting name to char to take care of empty strings.
< 0.001 
     12 
 101
name = char(name); 
 102 

 103 
% since this is a callback from the figure menu, it is possible that
 104 
% uimenufcn will give a bogus filename (one with a * in it) if we get
 105 
% any *'s in the filename, error out gracefully.
 106 
% might want to generalize this to the same set of chars windows prevents
 107 
% in filenames - could be crippling on unix though.
< 0.001 
     12 
 108
if any(name == '*') 
 109 
    error('MATLAB:saveas:invalidFilename','%s',...
 110 
         getString(message('MATLAB:saveas:invalidFilenameAsterisk', name)))
< 0.001 
     12 
 111
end 
 112 

 113 
% Make sure we can write given file. Note fileparts returns leaf directory in
 114 
% name return argument if given filename is only a path, i.e. 'c:\temp'.
  0.005 
     12 
 115
[fp,fn,fe]=fileparts(name); 
 116 

 117 
% Typecast fp, fe to char
 118 
% Avoid the inconsistency between "" 1x1 empty string and empty char arrays
< 0.001 
     12 
 119
fp = char(fp); 
 120 
% String indexing does not work the same way as with chars.
< 0.001 
     12 
 121
fe = char(fe); 
 122 
% NOTE: this does not allow to say:
 123 
% saveas(gcf, 'foo.', '-fig')
 124 
% maybe that's OK...
 125 
% william - 11/98
< 0.001 
     12 
 126
if ~isempty(fe) && strcmp(fe, '.') 
 127 
    error('MATLAB:saveas:invalidFilename','%s',...
 128 
        getString(message('MATLAB:saveas:invalidFilenameExtension',name)));
< 0.001 
     12 
 129
end 
< 0.001 
     12 
 130
if isempty(fe) 
 131 
   fe = '.fig';
< 0.001 
     12 
 132
end 
< 0.001 
     12 
 133
if isempty(fn)  
 134 
    error('MATLAB:saveas:invalidFilename','%s',...
 135 
        getString(message('MATLAB:saveas:invalidFilenameFile',name)));
< 0.001 
     12 
 136
end 
  0.001 
     12 
 137
if ~isempty(fp) && ~exist(fp, 'dir') 
 138 
    error('MATLAB:saveas:invalidFilename','%s',...
 139 
        getString(message('MATLAB:saveas:invalidFilenameBadPath' ,name)))
< 0.001 
     12 
 140
end 
 141 

< 0.001 
     12 
 142
if nargin == 2 
< 0.001 
     12 
 143
    format = fe(2:end); %Do not want the '.' 
< 0.001 
     12 
 144
end 
 145 

 146 
%Exist does not seem to like its arguments to be string hence converting it
 147 
%to char - This happens when nargin > 2
< 0.001 
     12 
 148
format = char(format); 
 149 

 150 
%For some formats we have helper SAVEAS... functions
 151 
% make sure format is defined to prevent recursion into this file
  0.104 
     12 
 152
if ~isempty(format) && any( exist( ['saveas' format]) == [2 3 5 6] ) %#ok 
 153 
    feval( ['saveas' format], h, name )
 154 
    
< 0.001 
     12 
 155
else     
 156 
    %If FORMAT is specified, look first to see if it is an extension
 157 
    %we know is that of a PRINT output format. If not, look to see if
 158 
    %it is a PRINT supported device format specifier.
  0.161 
     12 
 159
    [ops,dev,ext] = printtables(printjob(h)); %#ok 
  0.006 
     12 
 160
    i = strmatch( format, ext ); %#ok 
 161 
    
< 0.001 
     12 
 162
    if length(i) >= 1 
 163 
        %Handle special cases, more then one device, i.e. format='ps'
< 0.001 
     12 
 164
        i = i(1); 
 165 
        
 166 
    elseif isempty(i)
 167 
        i = strmatch( format, dev, 'exact'  );
 168 
        if isempty(i)
 169 
            i = strmatch( format, dev  ); %#ok
 170 
            if ~isempty(i)
 171 
                %Need to handle cases of multiple devices, i.e. format='ljet'
 172 
                i = i(1);
 173 
            end
 174 
        end
< 0.001 
     12 
 175
    end 
 176 
    
 177 
    %FORMAT is a PRINT support ext or driver
< 0.001 
     12 
 178
    if isempty(i) 
 179 
        error(message('MATLAB:saveas:badFormat', format))
< 0.001 
     12 
 180
    else 
 10.916 
     12 
 181
        print( h, name, ['-d' dev{i}] ) 
< 0.001 
     12 
 182
        return 
 183 
    end
 184 
    
 185 
end

Other subfunctions in this file are not included in this listing.