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]
③ 结构体
>> 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]
相关文章推荐
- 【转】谈谈MATLAB中cell数据类型
- Matlab数据类型
- (转)matlab数据类型及其简单的使用方法
- matlab中用imshow()显示图像与图像矩阵的数据类型的关系
- C++中的自定义数据类型(结构体)解析
- matlab中用imshow()显示图像与图像矩阵的数据类型的关系
- Matlab 读混合数据类型文件 textscan
- Struct结构体是C/C++语言中用来自定义数据类型的
- matlab数据类型和转换
- C# 与 C++ 数据类型比较及结构体转换
- c 的 struct,没有结构体名的结构体数据类型
- VC++与Matlab混合编程之引擎操作详解(3)数据类型mxArray的操作
- matlab与c语言中的数据类型对照
- C#与C++数据类型比较及结构体转换(搜集整理二)
- matlab中的数据类型和显示精度
- 复合数据类型,结构体,联合,枚举
- C语言数据类型大小和结构体中变量的地址分配方法【整理】
- C#与C++数据类型比较及结构体转换(搜集整理二)
- VC++与Matlab混合编程之引擎操作详解(5)数据类型mxArray的操作
- C语言程序设计教程笔记_复杂数据类型_结构体