function SaveTemplate(path, filename) % % Abstract: % Save current figure template as an m-file function. % % Usage: % >> SaveTemplate([path], filename) % % where [] is the directory path string of the location to store the % function by the name provided with . If no [path] is specified % then the current path is taken. '.m' is appended if only the prefix of % the name is given in . % % A MATLAB script function is created from the skeletal elements % that make up a figure window, which reproduces the following: % % o all the figure properties from the original figure % o all the axes and their properties % o all text children of each of the axes and properties of each % text item. % % The SaveAs function does not save any inforamation about any graphical % user interfaces actions, such as any button down functions or uicontrols % or uimenus and their call backs. It also does not save any user data nor % does it retain xdata, ydata, zdata and hence does not plot lines, % patches, surfaces, and images. % % History: % o 15 August 1995 created function SaveTemplate as part of Prmenu, % by Sara Haines. % global LASTFIGURE if isempty(LASTFIGURE) curfig = gcf; else curfig = LASTFIGURE; end set(curfig,'Pointer','watch'); % if nargin == 1 filename = path; path = '.'; elseif nargin > 2 disp('SaveAs: Too many input parameters'); return; elseif nargin == 0 disp('SaveAs: Too many input parameters'); return; end figprop = [ ... 'Color ';... 'InvertHardcopy ';... 'Name ';... 'NextPlot ';... 'NumberTitle ';... 'PaperUnits ';... 'PaperOrientation';... 'PaperPosition ';... 'PaperType ';... 'Position ';... 'Units ';... 'Visible ';... 'Clipping ';... 'Tag '... ]; axesprop = [... 'AspectRatio ';... 'Box ';... 'CLim ';... 'CLimMode ';... 'Color ';... 'ColorOrder ';... 'DrawMode ';... 'ExpFontAngle ';... 'ExpFontName ';... 'ExpFontSize ';... 'ExpFontStrikeThrough';... 'ExpFontUnderline ';... 'ExpFontWeight ';... 'FontAngle ';... 'FontName ';... 'FontSize ';... 'FontStrikeThrough ';... 'FontUnderline ';... 'FontWeight ';... 'GridLineStyle ';... 'Layer ';... 'LineStyleOrder ';... 'LineWidth ';... 'MinorGridLineStyle ';... 'NextPlot ';... 'TickLength ';... 'TickDir ';... 'View ';... 'XColor ';... 'XDir ';... 'XGrid ';... 'XLim ';... 'XLimMode ';... 'XMinorGrid ';... 'XMinorTicks ';... 'XScale ';... 'XTick ';... 'XTickLabels ';... 'XTickLabelMode ';... 'XTickMode ';... 'YColor ';... 'YDir ';... 'YGrid ';... 'YLim ';... 'YLimMode ';... 'YMinorGrid ';... 'YMinorTicks ';... 'YScale ';... 'YTick ';... 'YTickLabels ';... 'YTickLabelMode ';... 'YTickMode ';... 'ZColor ';... 'ZDir ';... 'ZGrid ';... 'ZLim ';... 'ZLimMode ';... 'ZMinorGrid ';... 'ZMinorTicks ';... 'ZScale ';... 'ZTick ';... 'ZTickLabels ';... 'ZTickLabelMode ';... 'ZTickMode ';... 'Clipping ';... 'Tag ';... 'Visible ';... ]; textprop = [... 'Color '; ... 'EraseMode '; ... 'FontAngle '; ... 'FontName '; ... 'FontSize '; ... 'FontStrikeThrough '; ... 'FontUnderline '; ... 'FontWeight '; ... 'HorizontalAlignment'; ... 'Position '; ... 'Rotation '; ... 'String '; ... 'Units '; ... 'VerticalAlignment '; ... 'Tag '; ... 'Visible '; ... ]; labeltype = [... 'Title '; ... 'Xlabel'; ... 'Ylabel'; ... 'Zlabel'; ... ]; % append or change suffix to dot-m if not found in filename prefixname = strtok(filename, '.'); if isempty(findstr(filename, '.m')) filename = [prefixname '.m']; end % remove any file with same name and path if (exist([path '/' filename]) == 2 ) eval(['delete ''' sprintf('%s',[path '/' filename]) '''']); end [fid, mesg] = fopen([path '/' filename], 'wt'); if (fid) < 0 disp(['SaveAs: Error opening file: ' mesg]); return; end % write function and header comments fprintf(fid, '%s\n', ['function ' prefixname '()']); fprintf(fid, '%s\n', ['% This function was generated by another '... 'function. It regenerates']); fprintf(fid, '%s\n', ['% a figure template as saved by function SaveAs.']); fprintf(fid, '%s\n', ['% ']); fprintf(fid, '%s\n', ['% Usage: Type the name of the function. ']); fprintf(fid, '%s\n', ['% >> ' prefixname]); fprintf(fid, '%s\n\n', ['% ']); fprintf(fid, '%s\n\n', ['A = figure;']); [Nfigprop, Mfigprop] = size(figprop); for element=1:Nfigprop prop = deblank(figprop(element,:)); propvalue = get(curfig, prop); if ~isstr(propvalue) [n,m] = size(propvalue); str = '['; for i=1:n if i>1 str = [str, sprintf('\t\t')]; end for j=1:m str = [str, sprintf('%s,', num2str(propvalue(i,j)))]; end if i1 str = [str, sprintf('\t\t')]; end for j=1:m str = [str, sprintf('%s,', num2str(propvalue(i,j)))]; end if i1 str = '['; for i=1:n if i>1 str = [str, sprintf('\t\t')]; end str = [str, sprintf(['''%' int2str(m) 's'''], propvalue(i,1:m))]; if i1 str = [str, sprintf('\t\t')]; end for j=1:m str = [str, sprintf('%s,', num2str(propvalue(i,j)))]; end if i1 str = [str, sprintf('\t\t')]; end for j=1:m str = [str, sprintf('%s,', num2str(propvalue(i,j)))]; end if i