
本页面提供的是上一版软件的文档。当前版本中已删除对应的英文页面。
下面的样例说明了怎样创建结构体数组。结构体是使用被称为字段的数据容器将相关数据组合在一起的一种数据类别。每个数组都可以包括任意类别或任意大小的数据。
将患者记录存储在带有字段 name、billing 和 test 的标量结构体中。

patient(1).name = 'John Doe';
patient(1).billing = 127.00;
patient(1).test = [79, 75, 73; 180, 178, 177.5; 220, 210, 205];
patient
patient = struct with fields:
name: 'John Doe'
billing: 127
test: [3x3 double]

通过在函数名称后添加下标,可在此数组中添加其它患者的记录。

patient(2).name = 'Ann Lane';
patient(2).billing = 28.50;
patient(2).test = [68, 70, 68; 118, 118, 119; 172, 170, 169];
patient
patient = 1x2 struct array with fields:
name
billing
test
数组中的每条患者记录都是 struct 类的结构体。由结构体构成的变量一般称为结构体数组。与其它 MATLAB 数组类似结构体数组结构体数组,结构体数组可以带有任意维度。
结构体数组具有下列属性:

数组中新结构体的任何已指定主键均包括空函数。
patient(3).name = 'New Name';
patient(3)
ans = struct with fields:
name: 'New Name'
billing: []
test: []
访问结构体数组中的数据,看一下第一名患者有多少欠款,并按照其检测结果创建一个条形图。
amount_due = patient(1).billing
amount_due = 127

bar(patient(1).test)
title(['Test Results for ', patient(1).name])

A modified version of this example exists on your system. Do you want to open this version instead? (zh_CN)
No, overwrite the modified version (zh_CN)Yes (zh_CN)
您点击了调用下列 MATLAB 命令的链接:

Web 浏览器不支持 MATLAB 命令。请在 MATLAB 命令窗口中直接输入该命令以运行它。
×
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
日本 (日本語) ()
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-134243-1.html
对美国只有一句话