matlab基础知识isfield

来源:互联网 发布:天天有喜知画是什么 编辑:程序博客网 时间:2024/05/18 01:18

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? 1Is 'salary' a field of student structure? 0

运行结果:

ans =     1     0     1






0 0
原创粉丝点击