summary
输出表、时间表或分类数组的摘要
说明
示例
表的摘要
创建一个表。
load patients BloodPressure = [Systolic Diastolic]; T = table(Gender,Age,Smoker,BloodPressure,'RowNames',LastName);
向表 T
中添加描述和单位。您可以为整个表添加描述,也可以为单个变量添加描述。
T.Properties.Description = 'Simulated patient data'; T.Properties.VariableUnits = {'' 'Yrs' '' 'mm Hg'}; T.Properties.VariableDescriptions{4} = 'Systolic/Diastolic';
输出表 T
的摘要。
format compact
summary(T)
Description: Simulated patient data Variables: Gender: 100x1 cell array of character vectors Age: 100x1 double Properties: Units: Yrs Values: Min 25 Median 39 Max 50 Smoker: 100x1 logical Values: True 34 False 66 BloodPressure: 100x2 double Properties: Units: mm Hg Description: Systolic/Diastolic Values: Column 1 Column 2 ________ ________ Min 109 68 Median 122 81.5 Max 138 99
summary
显示变量 BloodPressure
的每列的最小值、中位数和最大值。
时间表的摘要
创建一个较小的时间表。
Time = [seconds(1:5)]'; TT = timetable(Time,[98;97.5;97.9;98.1;97.9],[120;111;119;117;116],... 'VariableNames',{'Reading1','Reading2'})
TT=5×2 timetable
Time Reading1 Reading2
_____ ________ ________
1 sec 98 120
2 sec 97.5 111
3 sec 97.9 119
4 sec 98.1 117
5 sec 97.9 116
输出时间表的摘要。summary
输出行时间的摘要,后跟变量的摘要。如果时间表是规则时间表,则 summary
还输出行时间之间的时间步的大小。
summary(TT)
RowTimes: Time: 5x1 duration Values: Min 1 sec Median 3 sec Max 5 sec TimeStep 1 sec Variables: Reading1: 5x1 double Values: Min 97.5 Median 97.9 Max 98.1 Reading2: 5x1 double Values: Min 111 Median 117 Max 120
以结构体形式返回表摘要
创建一个表。向表变量添加单位。然后显示前几行。
load patients BloodPressure = [Systolic Diastolic]; T = table(Gender,Age,Smoker,BloodPressure,'RowNames',LastName); T.Properties.VariableUnits = {'' 'Years' '' 'mm Hg'}; head(T,3)
Gender Age Smoker BloodPressure __________ ___ ______ _____________ Smith {'Male' } 38 true 124 93 Johnson {'Male' } 43 false 109 77 Williams {'Female'} 38 false 125 83
返回表的摘要。要以结构体形式返回摘要,请在使用 summary
函数时指定输出参数。
s = summary(T)
s = struct with fields:
Gender: [1x1 struct]
Age: [1x1 struct]
Smoker: [1x1 struct]
BloodPressure: [1x1 struct]
显示表变量 Age
的摘要。对于 T
的每个变量,输出参数 s
具有包含其摘要的字段。
s.Age
ans = struct with fields:
Size: [100 1]
Type: 'double'
Description: ''
Units: 'Years'
Continuity: []
Min: 25
Median: 39
Max: 50
NumMissing: 0
NumMissing
字段显示值为缺失值的元素数。在这种情况下,Age
不包含任何 NaN
值,因此 NumMissing
为零。summary
会为数值、duration
、datetime
和 categorical
变量包含 NumMissing
字段。
显示表中包含的最小年龄。您可以按名称访问摘要的任何字段。
s.Age.Min
ans = 25
显示表变量 Smoker
的摘要。您可以从 True
和 False
字段确定吸烟者和非吸烟者的数量。表变量摘要包含的信息取决于变量的数据类型。
s.Smoker
ans = struct with fields:
Size: [100 1]
Type: 'logical'
Description: ''
Units: ''
Continuity: []
True: 34
False: 66
以结构体形式返回时间表摘要
创建一个时间表。
Time = datetime({'2015-12-18 08:00:00';'2015-12-18 10:00:00';'2015-12-18 12:00:00'}); Temp = [37.3;39.1;42.3]; Pressure = [30.1;30.03;29.9]; TT = timetable(Time,Temp,Pressure)
TT=3×2 timetable
Time Temp Pressure
____________________ ____ ________
18-Dec-2015 08:00:00 37.3 30.1
18-Dec-2015 10:00:00 39.1 30.03
18-Dec-2015 12:00:00 42.3 29.9
以结构体形式返回时间表摘要。
s = summary(TT)
s = struct with fields:
Time: [1x1 struct]
Temp: [1x1 struct]
Pressure: [1x1 struct]
显示行时间的摘要。TimeStep
字段显示连续行时间之间的时间间隔为两小时。NumMissing
字段显示行时间向量中没有缺失值 (NaT
)。
s.Time
ans = struct with fields:
Size: [3 1]
Type: 'datetime'
Min: 18-Dec-2015 08:00:00
Median: 18-Dec-2015 10:00:00
Max: 18-Dec-2015 12:00:00
NumMissing: 0
TimeStep: 02:00:00
更改最后一个行时间,以使行时间之间具有不同的时间间隔。
TT.Time(3) = '2015-12-18 11:00:00';
TT
TT=3×2 timetable
Time Temp Pressure
____________________ ____ ________
18-Dec-2015 08:00:00 37.3 30.1
18-Dec-2015 10:00:00 39.1 30.03
18-Dec-2015 11:00:00 42.3 29.9
返回更新时间表的摘要。由于行时间之间的时间步不同,因此 TimeStep
字段具有 NaN
。
s = summary(TT); s.Time
ans = struct with fields:
Size: [3 1]
Type: 'datetime'
Min: 18-Dec-2015 08:00:00
Median: 18-Dec-2015 10:00:00
Max: 18-Dec-2015 11:00:00
NumMissing: 0
TimeStep: NaN
包括自定义属性的表摘要
从 R2018b 开始,您可以向表和时间表添加自定义属性。如果添加自定义属性,则表或时间表的摘要包括这些属性。
首先,创建一个表并为其某些预定义属性添加值。
load patients BloodPressure = [Systolic Diastolic]; T = table(Gender,Age,Smoker,BloodPressure,'RowNames',LastName); T.Properties.Description = 'Simulated patient data'; T.Properties.VariableUnits = {'' 'Yrs' '' 'mm Hg'}; T.Properties.VariableDescriptions{4} = 'Systolic/Diastolic';
使用 addprop
函数添加自定义属性。对于每个自定义属性,请指定名称。此外,指定每个自定义属性的值是否存储应用于表或单个表变量的元数据。
T = addprop(T,{'SourceFile','DataOrigin'},{'table','variable'});
将元数据值存储在自定义属性中。
T.Properties.CustomProperties.SourceFile = 'patients.mat'; T.Properties.CustomProperties.DataOrigin = {'census','census','self report','blood pressure reading'};
打印表的摘要。除 T.Properties.Description
之外,summary
函数不会显示整体应用于表的属性。因此,它不显示 T.Properties.CustomProperties.SourceFile
的值。但是,summary
会显示应用于表变量的属性。对于每个变量,summary
显示 T.Properties.CustomProperties.DataOrigin
中的对应值。
summary(T)
Description: Simulated patient data Variables: Gender: 100x1 cell array of character vectors Custom Properties: DataOrigin: census Age: 100x1 double Properties: Units: Yrs Custom Properties: DataOrigin: census Values: Min 25 Median 39 Max 50 Smoker: 100x1 logical Custom Properties: DataOrigin: self report Values: True 34 False 66 BloodPressure: 100x2 double Properties: Units: mm Hg Description: Systolic/Diastolic Custom Properties: DataOrigin: blood pressure reading Values: Column 1 Column 2 ________ ________ Min 109 68 Median 122 81.5 Max 138 99
以结构体形式返回摘要。每个字段都具有与一个表变量对应的结构体。
s = summary(T)
s = struct with fields:
Gender: [1x1 struct]
Age: [1x1 struct]
Smoker: [1x1 struct]
BloodPressure: [1x1 struct]
结构体 s.Age
存储 Age
变量的摘要。
s.Age
ans = struct with fields:
Size: [100 1]
Type: 'double'
Description: ''
Units: 'Yrs'
Continuity: []
Min: 25
Median: 39
Max: 50
NumMissing: 0
CustomProperties: [1x1 struct]
s.Age.CustomProperties
结构体存储 T.Properties.CustomProperties.DataOrigin
属性中的对应值。
s.Age.CustomProperties
ans = struct with fields:
DataOrigin: {'census'}
分类向量的摘要
创建一个 1×5 分类向量。
A = categorical({'plane' 'car' 'train' 'car' 'plane'})
A = 1x5 categorical
plane car train car plane
A
包含三个类别:car
、plane
和 train
。
输出 A
的摘要。
summary(A)
car plane train 2 2 1
car
显示于 A
的两个元素中,plane
显示于两个元素中,train
显示于一个元素中。
由于 A
为行向量,summary
水平列出所出现的每个类别。
分类数组中每列的摘要
基于一个数值数组创建 4×2 分类数组 A
。
X = [1 3; 2 1; 3 1; 4 2]; valueset = 1:3; catnames = {'red','green','blue'}; A = categorical(X,valueset,catnames)
A = 4x2 categorical
red blue
green red
blue red
<undefined> green
A
包含三个类别:red
、green
和 blue
。值 4
不包含在 categorical
函数的 valueset
输入中。因此,对应的元素 A(4,1)
未定义并且没有对应的类别。
输出 A
的摘要。
summary(A)
red 1 2 green 1 1 blue 1 1 <undefined> 1 0
red
在 A
的第一列中出现一次,在第二列中出现两次。
green
在 A
的第一列中出现一次,在第二列中出现一次。
blue
在 A
的第一列中出现一次,在第二列中出现一次。
A
仅包含一个未定义的元素。该元素位于第一列中。
分类数组中每行的类别计数
从一个数值数组创建一个 3×2 分类数组 A
。
A = categorical([1 3; 2 1; 3 1],1:3,{'red','green','blue'})
A = 3x2 categorical
red blue
green red
blue red
A
包含三个类别:red
、green
和 blue
。
输出 A
沿第二个维度的摘要。
summary(A,2)
red green blue 1 0 1 1 1 0 1 0 1
red
在 A
的第一行、第二行、第三行中各出现一次。
green
仅显示于一个元素中。该元素位于 A
的第二行中。
blue
在 A
的第一行中出现一次,在第三行中出现一次。
输入参数
T
— 输入表
表 | 时间表
输入表,指定为表或时间表。
A
— 分类数组
向量 | 矩阵 | 多维数组
分类数组,指定为向量、矩阵或多维数组。
dim
— 沿其运算的 A
的维度
正整数标量
沿其运算的 A
的维度,指定为正整数标量。如果未指定值,则默认值是大小不等于 1 的第一个数组维度。
以一个二维分类数组 A
为例:
如果 dim = 1
,则 summary(A,dim)
显示 A
的每列的类别计数。
如果 dim = 2
,则 summary(A,dim)
显示 A
的每行的类别计数。
如果 dim
大于 ndims(A)
,则 summary(A)
为每个类别返回大小与 A
相同的数组。summary
为对应类别中的元素返回 1
,否则返回 0
。
输出参数
s
— 表或时间表变量的摘要
标量结构体
表或时间表变量的摘要,以标量结构体形式返回。对于输入表 T
中的每个变量 T.
,输出结构体 VarName
s
包含字段 s.
,该字段包含该变量的摘要。VarName
如果 T
中的变量的名称不是有效的 MATLAB® 标识符,则 summary
会修改变量名以创建有效的字段名称,主要方法是删除空格并用下划线替换非 ASCII 字符。
对于每种数据类型,s.
都包含以下字段。您可以访问带有点索引的字段。例如,VarName
s.
返回名为 VarName
.Size
的表变量的大小。VarName
表或时间表变量的类型 | 变量摘要的字段 | 描述 |
---|---|---|
数值、 |
| 变量的大小,存储为数值数组 |
| 变量类型,存储为字符向量 | |
| 变量描述,存储为字符向量 | |
| 变量单位,存储为字符向量 | |
| 最小值 | |
| 中位数值 | |
| 最大值 | |
| 缺失值( | |
| 与变量关联的自定义属性的名称和值,存储为结构体 | |
逻辑值 |
| 变量的大小,存储为数值数组 |
| 变量类型,存储为字符向量 | |
| 变量描述,存储为字符向量 | |
| 变量单位,存储为字符向量 | |
|
| |
|
| |
| 与变量关联的自定义属性的名称和值,存储为结构体 | |
|
| 变量的大小,存储为数值数组 |
| 变量类型,存储为字符向量 | |
| 变量描述,存储为字符向量 | |
| 变量单位,存储为字符向量 | |
| 类别,存储为字符向量元胞数组 | |
| 每个类别中的元素数,存储为数值数组 | |
| 缺失值 ( | |
| 与变量关联的自定义属性的名称和值,存储为结构体 | |
其他 |
| 变量的大小,存储为数值数组 |
| 变量类型,存储为字符向量 | |
| 变量描述,存储为字符向量 | |
| 变量单位,存储为字符向量 | |
| 与变量关联的自定义属性的名称和值,存储为结构体 |
如果 T
是时间表,则 s
还有一个包含行时间摘要的字段。仅对于时间表行时间,摘要包括 TimeStep
字段。如果行时间按固定时间步单调递增或递减,则 TimeStep
具有数值。如果行时间不规则,则 TimeStep
为 NaN
。
时间表行时间摘要的字段 | 字段描述 |
---|---|
| 行时间向量的大小,存储为数值数组 |
| 数据类型,存储为字符向量 |
| 最小值 |
| 中位数值 |
| 最大值 |
| 缺失值( |
| 连续行时间之间的时间步(如果不规则,则为 |
详细信息
表摘要
表摘要显示 T.Properties.Description
中的表描述并后跟有关 T
的变量的信息。
该摘要包含以下有关变量的信息:
名称:大小和数据类型 -
T.Properties.VariableNames
中的变量名称、变量的大小以及变量的数据类型。单位 -
T.Properties.VariableUnits
中变量的单位。描述 -
T.Properties.VariableDescriptions
中变量的描述。自定义属性 - 来自
T.Properties.CustomProperties
的应用于变量的自定义属性的名称及其对应值。如果没有自定义属性,则省略此部分。值 - 仅为数值、逻辑、
categorical
、datetime
或duration
变量包含值信息。数值、
datetime
或duration
变量 - 最小值、中位数和最大值。此外,当该数值大于零时,还包括缺失值(NaN
或NaT
)的数量。逻辑变量 - 为
true
的值的数目以及为false
的值的数目。categorical
变量 - 每个类别中元素的数目。此外,当该数值大于零时,还包括未定义元素的数目。
如果 T
是时间表,则摘要包含与行时间向量对应的相同信息。
扩展功能
tall 数组
对行数太多而无法放入内存的数组进行计算。
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
此函数完全支持基于线程的环境。有关详细信息,请参阅在基于线程的环境中运行 MATLAB 函数。
分布式数组
使用 Parallel Computing Toolbox™ 在集群的组合内存中对大型数组进行分区。
此函数完全支持分布式数组。有关详细信息,请参阅Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox)。
版本历史记录
在 R2013b 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
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:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)