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

MATLAB(3)数据类型二(结构体和…

2017-04-03 18:12 169 查看
1、MATLAB的数据类型

③ 结构体

>> h.name='hello';

>> h.company='cloundsun';

>> h.age=20;

>> h.tel=[150 187 182];

>> h

h = 

       name: 'hello'

    company: 'cloundsun'

        age: 20
 

        tel: [150 187 182]

>> isstruct(h)  % 判断 h 是否为 结构体

ans =

     1

>> fieldnames(h)   %得到结构体 h 的成员名

ans = 

    'name'

    'company'

    'age'

    'tel'

>> isfield(h,'name')   % 判断 name 是否为 h 结构体 的成员

ans =

     1

>> isfield(h,'na')   % 判断 na 是否为 h 结构体 的成员

ans =

     0

>> rmfield(h,'age') %移除一个成员,得到一个新的结构体,但是 结构体 h不变

ans = 

       name: 'hello'

    company: 'cloundsun'

        tel: [150 187 182]

>> h

h = 

       name: 'hello'

    company: 'cloundsun'

        age: 20

        tel: [150 187 182]

>> getfield(h,'tel')    % 得到结构体中某个成员的值

ans =

   150   187   182

>> h

h = 

       name: 'hello'

    company: 'cloundsun'

        age: 20

        tel: [150 187 182]

④ 单元

>> k={1,'string',[150 187 182]}

k = 

    [1]    'string'    [1x3 double]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: