Post-processing/Analysis

Matlab

A utility function for processing variable length input argument list

% procVarArg Utility function for processing variable length input argument
% list
%
% Syntax
%   options = procVarArg(names, defaultValues, varArg)
%   [options, varargout] = procVarArg(names, defaultValues, varArg)
%
% Description
%   options = procVarArg(names, defaultValues, varArg) generates a comma
%   separated list and call struct, options, with k attribute names defined
%   in names (k by 1 matrix) and k default values defined in defaultValues
%   (k by 1 matrix). The property/value pairs that are explictly given in
%   varArg overwrite those in defaultValues. varArg is usually the variable
%   length input argument list, varargin, to the function calling
%   procVarArg.
%
%   [options, varargout] = procVarArg(names, defaultValues, varArg) stores
%   parameters from varArg that are not found in names in varargout.
%   Currently, vargargout support only one variable that will store all the
%   parameters not in names.
%
% See also varargin varargout

function [options,varargout] = procVarArg(names,defaultValues,varArg)

structInput=cell(2,length(names));
structInput(1,:)=names';
structInput(2,:)=defaultValues';
options=struct(structInput{:});

nVArgOut=max(nargout,1)-1;
if nVArgOut>1
    error('ternsurf:TooManyOutputVar','Too many output variables. Currently support at most two output variables.');
end
iVarArgOut=0;

nVarArg=size(varArg,2);
iVarArg=1;
flag=2;

while iVarArg<=nVarArg
    arg=varArg{iVarArg};
    if flag==1
        if ischar(arg)
            arg=lower(deblank(arg));
        end
        options.(names{iName,:})=arg;
        flag=2;
    elseif flag==2
        if ~ischar(arg)
           error('ternsurf:ParamNotString','Parameter name must be a string.',iVarArg);
        end
        iName=find(strncmpi(arg,names,length(arg)));
        if isempty(iName)
            flag=0;
            continue
        elseif length(iName)>1
            jName=find(strcmpi(arg,names));
            if length(jName)==1
                iName=jName;
            else
                allMatchedNames=['(',names{iName(1),:}];
                for jName=iName(2:length(iName))'
                    allMatchedNames=[allMatchedNames,', ',names{jName,:}];
                end
                allMatchedNames=[allMatchedNames,')'];
                error('ternsurf:AmbiguousParamName','Ambiguous parameter name: ',arg,allMatchedNames);
            end
        end
        flag=1;
    else
        iVarArgOut=iVarArgOut+1;
        varargout{iVarArgOut}=varArg{iVarArg};
    end
    iVarArg=iVarArg+1;
end

Default plot styles

Name the following file startup.m and put it in a directory in the MATLAB search paths.

% startup.m
%
% Set default values of several properties for the graphic object with
% handle 0, which is the root ancestor and default behavior for all plots.
% PropertyName is formed by concatenating the string 'Default', the object
% type (e.g., 'Figure', 'Axes', 'Line', and 'Text'), and the property name
% (e.g., 'Color', 'FontName', 'LineWidth').
%
% See also STARTUP SET

set(0, 'DefaultFigureColor', 'white', ...
'DefaultAxesColor', 'none', ...
'DefaultAxesFontAngle', 'normal', ...
'DefaultAxesFontName', 'Helvetica', ...
'DefaultAxesFontUnits', 'points', ...
'DefaultAxesFontSize', 24, ...
'DefaultAxesFontWeight', 'normal', ...
'DefaultAxesGridLineStyle', ':', ...
'DefaultAxesLayer', 'Bottom', ...
'DefaultAxesLineWidth', 2, ...
'DefaultAxesTickLength', [0.02,0.02], ...
'DefaultAxesUnits', 'inches', ...
'DefaultAxesPosition',[0.85 0.8 3.25 3.25],...
'DefaultAxesVisible', 'on', ...
'DefaultAxesXcolor', 'black', ...
'DefaultAxesYcolor', 'black', ...
'DefaultAxesZcolor', 'black', ...
'DefaultLineColor', 'black', ...
'DefaultLineLineStyle', '-', ...
'DefaultLineLineWidth', 2, ...
'DefaultLineMarker', 'none', ...
'DefaultLineMarkerSize', 9, ...
'DefaultTextColor', 'black', ...
'DefaultTextFontName', 'Helvetica', ...
'DefaultTextFontUnits', 'points', ...
'DefaultTextFontSize', 24, ...
'DefaultTextFontWeight', 'normal', ...
'DefaultTextHorizontalAlignment', 'left', ...
'DefaultTextInterpreter','latex', ...
'DefaultTextVerticalAlignment', 'middle' ...
);

Comments

Comments powered by Disqus