Matlab函数isfield
函数功能:判断输入是否是结构体数组的域(成员)
调用格式:
t = isfield(S,'fieldname')
检测结构体S是否包含有fieldname指定的域,如果包含,返回逻辑1;如果不不包含fieldname域或者S不是结构体类型的,则返回逻辑0;
t =isfield(S,C)
其中C是一个包含多个字符串的元胞数组,isfield判定由这些字符串表示的域是否是结构体的域。返回值是个逻辑型数组。
matlab例子:
student = struct('name', 'John', 'age', 20, 'score', 90); fprintf('Is ''name'' a field of student structure? %d\n',isfield(student, 'name')); fprintf('Is ''salary'' a field of student structure? %d\n',isfield(student, 'salary')); isfield(student, {'name', 'salary', 'score'}) Is 'name' a field of student structure? 1 Is 'salary' a field of student structure? 0
运行结果:
ans = 1 0 1
时间: 2024-10-20 05:22:20