当前位置:网站首页>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 x3
When 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,而不是删除它.
边栏推荐
猜你喜欢
随机推荐
CRT command keys
C language two-dimensional array is called with one-dimensional array
servlet生命周期详解--【结合源码】
Promise 二:关键问题
通过GBase 8c Platform安装数据库集群时报错
混合型界面:对话式UI的未来
Scapy的介绍(一)「建议收藏」
synchronized
STM32+OLED显示屏制作指针式电子钟
_GLIBCXX_USE_CXX11_ABI 宏的作用
HCIP第十七天笔记
Mysql OCP 75 questions
迅为IMX6开发板QT系统创建AP热点基于RTL8723交叉编译hostapd
三大产品力赋能欧萌达OMODA5
流水线设计的方法和作用「建议收藏」
Leecode-SQL 1527. 模糊查询匹配(模糊查询用法)
数字藏品和ICP
Scrapy + Selenium 实现模拟登录,获取页面动态加载数据
How to deal with this time of MySQL binlog??
2022年山东省安全员C证复习题模拟考试平台操作