MATLAB基本操作(四):结构体struct&元胞数组cell
来源:互联网 发布:mac充电器怎么用 编辑:程序博客网 时间:2024/05/20 08:27
一,结构体的使用
1)直接创建法:
- >> student.name='Tom';
- >> student.age=20;
- >> student.sex='male';
- >> student
- student =
- name: 'Tom'
- age: 20
- sex: 'male'
- >> student(1).name='Tom';
- student(1).age=20;
- student(1).sex='male';
- >> student(2).name='rose';
- student(2).age=21;
- student(2).sex='female';
- >> student
- student =
- 1x2 struct array with fields:
- name
- age
- sex
- >> student(1)
- ans =
- name: 'Tom'
- age: 20
- sex: 'male'
- >> student(2)
- ans =
- name: 'rose'
- age: 21
- sex: 'female'
2)用关键字struct创建
- >> student=struct('name',{'Tom','rose'},'age',{20,21});
- >> student
- student =
- 1x2 struct array with fields:
- name
- age
- >> student(1)
- ans =
- name: 'Tom'
- age: 20
- >> student(2)
- ans =
- name: 'rose'
- age: 21
3)要增加字段怎么办?直接在结构体名后加 .字段名
- student(1).id=100;
- student=rmfield(student,'id');
fieldnames(student); %返回字段名
isfield(student,'age');
isstruct(student);
struct2cell(student);
二,元胞数组
它与数组的区别是:每个元素可以是不同类型的,可是不同大小的矩阵,也可以是字符串,结构体等
使用元胞数组要区分(),{}的区别。
1)创建元胞数组
- >> c(1,1)={[1,2;3 4]};
- >> c(1,2)={'tom is a sb'};
- >> c(2,1)={[1,2,3,4,5,6]};
- >> c(2,2)={struct('name','rose','age',21)};
- >> c
- c =
- [2x2 double] 'tom is a sb'
- [1x6 double] [1x1 struct]
- >> c(1,1)
- ans =
- [2x2 double]
- >> c{1,1}
- ans =
- 1 2
- 3 4
- >>
{ }:可以返回一个元胞中的具体数据;
() :返回该位置的数组类型信息
- >> B(3,3)={'hello'};
- >> B
- B =
- [] [] []
- [] [] []
- [] [] 'hello'
- >>
创建一个3*3的元胞数组,并组在(3,3)位置的赋值
celldisp(c); %显示
cell2struct();
num2cell();
iscell();
总结:1)struct和cell看起来是像相似的,其实可以这样理解struct只能过构造1*n个元素,而cell就是个变态版的数 组;
2)他们真的没什么联系~~~
0 0
- MATLAB基本操作(四):结构体struct&元胞数组cell
- MATLAB基本操作(四):结构体struct&元胞数组cell
- 关于Matlab下的cell元胞与struct结构体
- MATLAB元胞数组(cell) I
- MATLAB元胞数组(cell) II
- matlab—元胞数组cell
- matlab 结构(struct)数组
- matlab结构(struct)数组
- matlab 结构(struct)数组
- Matlab元胞数组操作
- Matlab新建struct结构体数组
- cell元胞数组
- Matlab中的结构(struct)数组
- MATLAB中使用结构体 -- 结构(struct)数组
- [Matlab]结构体(Struct)
- matlab 结构体struct
- matlab struct 结构体
- matlab-结构体struct
- MATLAB基本操作(五):MATLAB中的逻辑运算及all(),any()的使用
- win7(32/64)+php5.5+apache2.4+mysql5.6 搭建
- IOS-Apple Swift编程语言入门教程
- 利用jsonrpc技术包装uiautomator
- Swift简明教程(一)变量与常量
- MATLAB基本操作(四):结构体struct&元胞数组cell
- 文件系统概述
- Lua 标准库 - 基本函数(base function)
- php XPATH一些注意事项
- RGB,HSV
- tcp http 区别
- MATLAB与图像处理(三):图像分成块
- java String 之参数传递
- 数据清洗与收集week1