forked from pdollar/toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
68 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
||
|