当前位置:网站首页>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,而不是删除它.
边栏推荐
猜你喜欢
随机推荐
Scrapy + Selenium implements simulated login and obtains dynamic page loading data
C language two-dimensional array is called with one-dimensional array
This article understands the process from RS485 sensor to IoT gateway to cloud platform
cass9.1快捷键怎么设置_cass9.1格式刷快捷键命令
安全研究员:大量Solana钱包被盗
servlet生命周期详解--【结合源码】
Go Redis database operation
一文了解,从RS485传感器到物联网关到云平台过程
QT with OpenGL(Shadow Mapping)(面光源篇)
混合型界面:对话式UI的未来
57.【全排列的详细分析】
浪潮—英伟达打造元宇宙新方案,虚拟人的故事将再破你的认知
像用户体验设计师一样思考
OPENCV学习DAY7
后台图库上传功能
STM32+OLED显示屏制作指针式电子钟
金先生谈长效生长激素出海与产品力
Boolean 与numeric 无法互转
Regulation action for one hundred days during the summer, more than 700 traffic safety hidden dangers were thrown out
Promise 2: Key Questions









