Skip to content

Commit

Permalink
standardized
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://lumo.ucsd.edu/projects/p1/svnroot/pdollar/toolbox@3787 52fe0c90-79fe-0310-8a18-a0b98ad248f8
  • Loading branch information
pdollar committed Jan 10, 2007
1 parent 4d342cd commit c5ade1e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 59 deletions.
47 changes: 25 additions & 22 deletions matlab/figureresized.m
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
% Creates a figures that takes up certain area of screen.
%
% Almost same as figure, except get to specify what fraction of available screen space
% figure should take up. Figure appears in center of screen.
% Almost same as figure, except get to specify what fraction of available
% screen space figure should take up. Figure appears in center of screen.
%
% USAGE
% varargout = figureresized( screenratio, varargin )
%
% INPUTS
% screenratio - controls fraction of screen image takes out (<=.8)
% varargin - parameters to figure
% screenratio - controls fraction of screen image takes out (<=.8)
% varargin - parameters to figure
%
% OUTPUTS
% varargin - parameters from figure
% varargout - out from figure
%
% EXAMPLE
% figureresized( .75 )
% figureresized( .75 )
%
% DATESTAMP
% 18-Aug-2006 2:00pm
% 10-Jan-2007 10:00am
%
% See also FIGURE

Expand All @@ -23,20 +26,20 @@
% Please email me if you find bugs, or have suggestions or questions!

function varargout = figureresized( screenratio, varargin )
if( nargin<1 ) screenratio=.3; end;
if( screenratio>1 ) error('screenratio must be <= 1'); end;
% call figure
h = figure( varargin{:} );
if( nargout ) varargout = {h}; end;
% get dimensions of screen and what want figure to be
units = get(0,'Units');
ss = get(0,'ScreenSize');
st = (1 - screenratio)/2;
pos = [st*ss(3), st*ss(4), screenratio*ss(3), screenratio*ss(4)];
if( nargin<1 ); screenratio=.3; end;
if( screenratio>1 ); error('screenratio must be <= 1'); end;

% call figure
h = figure( varargin{:} );
if( nargout ); varargout = {h}; end;

% get dimensions of screen and what want figure to be
units = get(0,'Units');
ss = get(0,'ScreenSize');
st = (1 - screenratio)/2;
pos = [st*ss(3), st*ss(4), screenratio*ss(3), screenratio*ss(4)];

% set dimensions of figure
set( h, 'Units', units );
set( h, 'Position', pos );
% set dimensions of figure
set( h, 'Units', units );
set( h, 'Position', pos );

80 changes: 43 additions & 37 deletions matlab/isfield2.m
Original file line number Diff line number Diff line change
@@ -1,57 +1,63 @@
% More comprehensive version of isfield.
%
% A more comprehensive test of what fields are present [and optionally initialized] in a
% stuct S. fs is either a single field name or a cell array of field name. The presence
% of all fields in fs are tested for in S, tf is true iif all fs are present.
% Additionally, if isinit==1, then tf is true iff every field fs of every element of S
% is nonempty (test done using isempty).
% A more comprehensive test of what fields are present [and optionally
% initialized] in a stuct S. fs is either a single field name or a cell
% array of field name. The presence of all fields in fs are tested for in
% S, tf is true iif all fs are present. Additionally, if isinit==1, then tf
% is true iff every field fs of every element of S is nonempty (test done
% using isempty).
%
% USAGE
% tf = isfield2( S, fs, [isinit] )
%
% INPUTS
% S - struct array
% fs - cell of string name or string
% isinit - [optional] if true than additionally test if all fields are initialized
% S - struct array
% fs - cell of string name or string
% [isinit] - if true than additionally test if all fields are initialized
%
% OUTPUTS
% tf - true or false, depending on results of above tests
% tf - true or false, depending on results of above tests
%
% DATESTAMP
% 29-Sep-2005 2:00pm
% 10-Jan-2007 10:00am
%
% See also ISFIELD

% Piotr's Image&Video Toolbox Version 1.03
% Written and maintained by Piotr Dollar pdollar-at-cs.ucsd.edu
% Please email me if you find bugs, or have suggestions or questions!

function tf = isfield2( S, fs, isinit )
if( nargin<3 ) isinit=0; end;
if( nargin<3 ); isinit=0; end;

if ~isa(S,'struct')
tf = false; return;
end;
% check if fs is a cell array, if not make it so
if( iscell(fs) )
nfs = length(fs);
else
nfs=1; fs={fs};
end;
% see if every one of fs is a fieldname
Sfs = fieldnames(S);
tf = true;
for i=1:nfs
tf = tf & any(strcmp(Sfs,fs{i}));
if( ~tf ) return; end;
end;
if ~isa(S,'struct')
tf = false; return;
end;

% check if fs is a cell array, if not make it so
if( iscell(fs) )
nfs = length(fs);
else
nfs=1; fs={fs};
end;

% see if every one of fs is a fieldname
Sfs = fieldnames(S);
tf = true;
for i=1:nfs
tf = tf & any(strcmp(Sfs,fs{i}));
if( ~tf ); return; end;
end;

% now optionally check if fields are isinitialized
if( ~isinit || ~tf ) return; end;
nS = numel(S);
for i=1:nfs
for j=1:nS
tf = tf & ~isempty( getfield(S(j),fs{i}) );
if( ~tf ) return; end;
end;
% now optionally check if fields are isinitialized
if( ~isinit || ~tf ); return; end;
nS = numel(S);
for i=1:nfs
for j=1:nS
tf = tf & ~isempty( S(j).(fs{i}) );
if( ~tf ); return; end;
end;
end;



0 comments on commit c5ade1e

Please sign in to comment.