📄 hasfields.m
字号:
function bvalue = hasfields(teststruct, varargin)
% hasfields - test whether a struct has the same fields as a template
%
% FORMAT: boolval = hasfields(teststruct, template [, onlythese])
%
% Input fields:
%
% teststruct struct array that is tested
% template template struct that will be used
% onlythese optional argument, if given only returns true if no
% other fields are presents in teststruct
%
% Note: the order of the fieldnames is irrelevant for the test!
%
% See also ISFIELD.
% Version: v0.5c
% Build: 6120415
% Date: Dec-04 2006, 3:15 PM CET
% Author: Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools
% argument check
if nargin < 2 || ...
~isstruct(teststruct) || ...
~isstruct(varargin{1})
error( ...
'BVQXtools:BadArgument', ...
'Too few or bad input arguments given.' ...
);
end
template = varargin{1};
% init return value
bvalue = false;
% get fieldnames
does = fieldnames(teststruct);
must = fieldnames(template);
% return false if number of fields mismatch
if nargin > 2 && ...
length(does) ~= length(must)
return;
end
% test every must-fields
for fc = 1:length(must)
if ~any(strcmp(does,must{fc}))
return;
end
end
% all checks passed
bvalue = true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -