MATLAB中rmfield函数用法

目录

语法

说明

示例

删除单个字段

删除多个字段


        rmfield函数的功能是删除结构体中的字段。

语法

s = rmfield(s,field)

说明

        s = rmfield(s,field) 从结构体数组 s 中删除指定的一个或多个字段。使用字符向量元胞数组或字符串数组指定多个字段。s 的维度保持不变。

示例

删除单个字段

        定义一个包含名为 a、b 和 c 的字段的标量结构体。

s.a = 1;
s.b = 2;
s.c = 3;

        删除字段 b。

field = 'b';
s = rmfield(s,field)
s = struct with fields:
    a: 1
    c: 3

删除多个字段

        定义一个包含 first、second、third 和 fourth 字段的标量结构体。

S.first = 1;
S.second = 2;
S.third = 3;
S.fourth = 4;

        删除字段 first 和 fourth。

fields = {'first','fourth'};
S = rmfield(S,fields)
S = struct with fields:
    second: 2
     third: 3

参数说明

s — 输入结构体

        输入结构体,指定为结构体数组。

field — 字段名称

        字段名称,指定为字符数组、字符向量元胞数组或字符串数组。

你可能感兴趣的:(Matlab,matlab,开发语言)