[Index for tmp_for_tar/struct]
[Return to Master Index]
cmpstruct
(tmp_for_tar/struct/cmpstruct.m)
Function Synopsis
c = cmpstruct(s1,s2)
Help text
c = cmpstruct (s1,s2) - Compare structs
Compares two structs, returning 1 if they are equal, 0 otherwise.
Will work only if fields of s1 and s2 can be compared through the
'cmpany' function.
See also fields, getfield, setfield, rmfield, isfield, isstruct,
struct.
Has not been optimized.
Last modified: January 2000
Cross-Reference Information
This function calls
- sayif tmp_for_tar/struct/sayif.m
Listing of function file tmp_for_tar/struct/cmpstruct.m
## c = cmpstruct (s1,s2) - Compare structs
##
## Compares two structs, returning 1 if they are equal, 0 otherwise.
##
## Will work only if fields of s1 and s2 can be compared through the
## 'cmpany' function.
##
## See also fields, getfield, setfield, rmfield, isfield, isstruct,
## struct.
##
## Has not been optimized.
## Author: Etienne Grossmann <etienne@isr.ist.utl.pt>
## Last modified: January 2000
function c = cmpstruct(s1,s2)
c = 1 ;
verbose = 0 ;
if !is_struct(s1) || !is_struct(s2) ,
printf('cmpstruct called with non-struct\n') ;
keyboard
end
for [val,key] = s1 ,
# if ! struct_contains(s2,key) ||...
# eval(sprintf( ...
# 'any(size(s1.%s)!=size(s2.%s)) || any(any(s1.%s != s2.%s));',...
# key,key,key,key) ) ,
# c = 0 ; return ;
# end
if ! struct_contains(s2,key) ||...
! eval(sprintf("cmpany(s1.%s,s2.%s);",key,key)) ,
sayif(verbose,"cmpstruct : Values for '%s' differ\n",key) ;
c = 0 ; return ;
end
sayif(verbose>1,"cmpstruct : Values for '%s' are equal\n",key) ;
end
for [val,key] = s2 ,
# if ! struct_contains(s1,key) ||...
# eval(sprintf(...
# 'any(size(s1.%s)!=size(s2.%s)) || any(any(s1.%s != s2.%s));',...
# key,key,key,key) ) ,
# c = 0 ; return ;
# end
if ! struct_contains(s1,key) ||...
! eval(sprintf("cmpany(s1.%s,s2.%s);",key,key)) ,
sayif(verbose,"cmpstruct : Values for '%s' differ\n",key) ;
c = 0 ; return ;
end
sayif(verbose>1,"cmpstruct : Values for '%s' are equal\n",key) ;
end
Produced by oct2html on Wed Aug 8 19:47:02 2001
Cross-Directory links are: ON