当前位置:网站首页>MATLAB programming and application 2.7 Structural data and unit data
MATLAB programming and application 2.7 Structural data and unit data
2022-08-03 10:34:00 【丁Jiaxiong】
MATLAB程序设计与应用
2. 第2章 MATLAB数据及其运算
2.7 Structural data and unit data
从MATLAB 5.0 开始,MATLABTwo new data types have been added:Structural data types and cell data types.Both data types integrate different related data into a single variable,It simplifies the processing and reference of a large amount of related data、方便.
2.7.1 结构数据
Structural data types combine a set of data of different types and logically related to form the whole of a month machine,for easy management and reference.For example, to store the basic information of students, the structured data type can be used.
Construction and reference of the structure matrix
The elements of the structure matrix can be of different data types,It can incorporate a set of data with different properties into one system:Managed under a variable name.A structure matrix can be established by assigning values to structure members.
格式:
structure matrix name.成员名 = 表达式表达式 → 矩阵表达式
建立含有3element structure matrixa
>> a(1).x1 = 10; a(1).x2 = 'liu'; a(1).x3 = [11,21;34,78]; >> a(2).x1 = 12; a(2).x2 = 'wang'; a(2).x3 = [34,191;27,578]; >> a(3).x1 = 12; a(3).x2 = 'cai'; a(3).x3 = [13,890;67,231];Members of a structure matrix element can also be structure data.
>> a(2).x1.x11 = 90; >> a(2).x1.x12 = 12; >> a(2).x1.x13 = 30;A reference to structured data,Its members can be referenced,It is also possible to refer to elements of a structure matrix or to structure variables.
>> a(2).x3 ans = 34 191 27 578 >> a(2) ans = 包含以下字段的 struct: x1: [1×1 struct] x2: 'wang' x3: [2×2 double] a = 包含以下字段的 1×3 struct 数组: x1 x2 x3When referencing a member of a structure matrix element,显示其值.When referencing a structure matrix element,Displays the member name and its value,But when the member is a matrix,Its specific content is not displayed,Only the membership matrix size parameter is displayed.When referencing a struct matrix,Only the size parameters and member names of the structure matrix are displayed.
Modification of structure members
Members of the structure can be added or removed as needed.
给aAdd members to any of the elementsx4
>> a(1).x4 = '410075'; >> a(1) ans = 包含以下字段的 struct: x1: 10 x2: 'liu' x3: [2×2 double] x4: '410075'Remove a member of a structure,则可以使用rmfield函数完成.
>> a = rmfield(a , 'x4'); >> a a = 包含以下字段的 1×3 struct 数组: x1 x2 x3
2.7.2 单元数据
Cell data types are similar to struct data types,It is also to put the data of different attributes in a variable.所不同的是,There are members under each element of the structure matrix,每个成员都有自己的名字,A reference to a member:structure matrix name.成员名,而单元矩阵的各个元素就是不同类型的数据,Cell matrix elements are referenced with braced subscripts.
Build the cell matrixb
>> b = {10,'liu',[11,21;34,78];12,'wang',[34,191;27,578];14,'cai',[13,890;67,231]}
b =
3×3 cell 数组
{[10]} {'liu' } {2×2 double}
{[12]} {'wang'} {2×2 double}
{[14]} {'cai' } {2×2 double}
Cell matrix elements can be referenced with curly braced subscripts
>> b{3,3}
ans =
13 890
67 231
The elements of the cell matrix can be structures or cell data.
>> y.x1 = 34; y.x2 = 56;
>> b{3,4} = y;
>> b
b =
3×4 cell 数组
{[10]} {'liu' } {2×2 double} {0×0 double}
{[12]} {'wang'} {2×2 double} {0×0 double}
{[14]} {'cai' } {2×2 double} {1×1 struct}
可以使用celldisp function to display the entire cell matrix.
>> celldisp(b)
b{1,1} =
10
b{2,1} =
12
b{3,1} =
14
b{1,2} =
liu
b{2,2} =
wang
b{3,2} =
cai
b{1,3} =
11 21
34 78
b{2,3} =
34 191
27 578
b{3,3} =
13 890
67 231
b{1,4} =
[]
b{2,4} =
[]
b{3,4} =
x1: 34
x2: 56
It is also possible to delete elements in the cell matrix using an empty matrix
>> b(3) = []
b =
1×11 cell 数组
列 1 至 7
{[10]} {[12]} {'liu'} {'wang'} {'cai'} {2×2 double} {2×2 double}
列 8 至 11
{2×2 double} {0×0 double} {0×0 double} {1×1 struct}
b(3) = [] 之后,binto a row vector
b{3} = [] 是将b的第3elements are set to the empty matrix,而不是删除它.
边栏推荐
猜你喜欢
随机推荐
mysql数据库定时备份占用大量线程,导致全局锁表,有啥好的解决方法么
Mysql OCP 26题
Mysql OCP 75 questions
文旅部:进一步加强旅游景区暑期安全管理工作
机器学习(公式推导与代码实现)--sklearn机器学习库
玉溪卷烟厂通过正确选择时序数据库 轻松应对超万亿行数据
分布式事务七种解决方案
分辨率_分辨率越高越好?手机屏幕分辨率多少才合适?现在终于搞清楚了[通俗易懂]
DOM0、DOM2、DOM3 事件
被审稿人吐槽没有novelty!深度学习方向怎么找创新点?
函数指针数组
深度学习经典网络 -- Inception系列(稀疏结构)
GBase 8c分布式数据库,数据如何分布最优?
Boolean 与numeric 无法互转
如何改变sys_guid() 返回值类型
Mysql OCP 74 questions
MySql数据库索引优化
SQL教程之递归 CTE Common Table Expression
57.【全排列的详细分析】
507. 完美数









