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]