您的位置:首页 > 编程语言 > MATLAB

Matlab函数isfield简介

2018-03-07 09:32 387 查看
http://blog.sina.com.cn/s/blog_c8830d820101cn79.html
函数功能: 判断输入是否是结构体数组的域(成员)。调用格式: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 =     1     0     1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: