目录
datastore函数的功能是为大型数据集合创建数据存储。
语法
ds = datastore(location)
ds = datastore(location,Name,Value)
说明
ds = datastore(location) 根据 location 指定的数据集合创建一个数据存储。数据存储是一个存储库,用于收集由于体积太大而无法载入内存的数据。创建 ds 后,可以读取并处理数据。
ds = datastore(location,Name,Value) 使用一个或多个名称-值对组参数为 ds 指定其他参数。例如,可以通过指定 'Type','image' 为图像文件创建数据存储。
示例
为文本数据创建数据存储
创建一个与示例文件 airlinesmall.csv 关联的数据存储。此文件包含从 1987 至 2008 年的航空公司数据。
要控制如何在数值列中导入缺失的数据,请使用 "TreatAsMissing" 和 "MissingValue" 名称-值参数。通过将 "TreatAsMissing" 的值指定为 "NA" 并将 "MissingValue" 的值指定为 0,在导入的数据中用 0 替换每个 "NA" 实例。
ds = datastore("airlinesmall.csv","TreatAsMissing","NA",...
"MissingValue",0)
ds =
TabularTextDatastore with properties:
Files: {
'B:\matlab\toolbox\matlab\demos\airlinesmall.csv'
}
Folders: {
'B:\matlab\toolbox\matlab\demos'
}
FileEncoding: 'UTF-8'
AlternateFileSystemRoots: {}
VariableNamingRule: 'modify'
ReadVariableNames: true
VariableNames: {'Year', 'Month', 'DayofMonth' ... and 26 more}
DatetimeLocale: en_US
Text Format Properties:
NumHeaderLines: 0
Delimiter: ','
RowDelimiter: '\r\n'
TreatAsMissing: 'NA'
MissingValue: 0
Advanced Text Format Properties:
TextscanFormats: {'%f', '%f', '%f' ... and 26 more}
TextType: 'char'
ExponentCharacters: 'eEdD'
CommentStyle: ''
Whitespace: ' \b\t'
MultipleDelimitersAsOne: false
Properties that control the table returned by preview, read, readall:
SelectedVariableNames: {'Year', 'Month', 'DayofMonth' ... and 26 more}
SelectedFormats: {'%f', '%f', '%f' ... and 26 more}
ReadSize: 20000 rows
OutputType: 'table'
RowTimes: []
Write-specific Properties:
SupportedOutputFormats: ["txt" "csv" "xlsx" "xls" "parquet" "parq"]
DefaultOutputFormat: "txt"
datastore 创建一个 TabularTextDatastore。
为图像数据创建数据存储
创建一个包含 MATLAB® 路径及其子文件夹中的所有 .tif 文件的数据存储。
ds = datastore(fullfile(matlabroot,"toolbox","matlab"),...
"IncludeSubfolders",true,"FileExtensions",".tif","Type","image")
ds = ImageDatastore with properties:
Files: {
'H:\matlab\toolbox\matlab\demos\example.tif';
'H:\matlab\toolbox\matlab\imagesci\corn.tif'
}
Folders: {
'H:\matlab\toolbox\matlab'
}
AlternateFileSystemRoots: {}
ReadSize: 1
Labels: {}
SupportedOutputFormats: ["png" "jpg" "jpeg" "tif" "tiff"]
DefaultOutputFormat: "png"
ReadFcn: @readDatastoreImage