isfield

isfieldMatlab函式isfield简介
【isfield】函式功能: 判断输入是否是结构体数组的域(成员) 。
调用格式:tf = isfield(S, 'fieldname')检查结构体S是否包含由fieldname指定的域,如果包含,返回逻辑1; 如果S不包含fieldname域或者S不是结构体类型的,返回逻辑0 。tf = isfield(S, C)其中C是一个包含多个字元串的元胞数组,isfield判定由这些字元串表示的域是否是结构体的域 。返回值是个逻辑型数组 。程式示例close all; clear; clc;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? 0ans =101