主要内容

partition

分区数据存储

描述

example

subds= partition(ds,n,指数)分区数据存储dsinto the number of parts specified byn并返回与索引相对应的分区指数.

example

subds= partition(ds,'Files',指数)partitions the datastore by files and returns the partition corresponding to the file of index指数在里面Filesproperty.

subds= partition(ds,'Files',filename)通过文件对数据存储进行分区,并返回与与文件指定的文件相对应的分区filename.

例子

全部收缩

创建一个数据存储,用于大量文件集合。在此示例中,使用示例文件的十本AirlinesMall.CSV. To handle missing fields in the tabular data, specify the name-value pairs治疗失踪值.

files = repmat({'airlinesmall.csv'},1,10); ds = tabularTextDatastore(files,...'TreatAsMissing','na',“失踪价值”,0);

将数据存储分为三个部分,然后返回第一个分区。这partitionfunction returns approximately the first third of the data from the datastoreds.

subds = partition(ds,3,1)
subds = TabularTextDatastore with properties: Files: { ' ...\matlab\toolbox\matlab\demos\airlinesmall.csv'; ' ...\matlab\toolbox\matlab\demos\airlinesmall.csv'; ' ...\matlab\toolbox\matlab\demos\airlinesmall.csv' ... and 1 more } FileEncoding: 'UTF-8' AlternateFileSystemRoots: {} ReadVariableNames: true VariableNames: {'Year', 'Month', 'DayofMonth' ... and 26 more} 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

Files数据存储的属性包含数据存储中包含的文件列表。检查在Files数据存储的属性ds和the partitioned datastoresubds. The datastoreds包含十个文件和分区subds包含前四个文件。

length(ds.Files)
ANS = 10
length(subds.Files)
ans = 4

从示例文件创建数据存储,mapredout.mat, which is the output file of theMapReducefunction.

ds = datastore('mapredout.mat');

Get the default number of partitions fords.

n = numpartitions(ds);

Partition the datastore into the default number of partitions and return the datastore corresponding to the first partition.

subds =分区(ds,n,1);

Read the data insubds.

尽管hasdata(subds) data = read(subds);end

Create a datastore that contains three image files.

ds = imagedatastore({'Street1.jpg','peppers.png','corn.tif'})
ds = ImageDatastore with properties: Files: { ' ...\matlab\toolbox\matlab\demos\street1.jpg'; ' ...\matlab\toolbox\matlab\imagesci\peppers.png'; ' ...\matlab\toolbox\matlab\imagesci\corn.tif' } ReadSize: 1 Labels: {} ReadFcn: @readDatastoreImage

通过文件对数据存储进行分区,然后返回与第二个文件相对应的零件。

subds = partition(ds,“文件”,2)
subds = ImageDatastore with properties: Files: { ' ...\matlab\toolbox\matlab\imagesci\peppers.png' } ReadSize: 1 Labels: {} ReadFcn: @readDatastoreImage

subds包含一个文件。

从示例文件创建数据存储,mapredout.mat, which is the output file of theMapReducefunction.

ds = datastore('mapredout.mat');

Partition the datastore into three parts on three workers in a parallel pool.

numWorkers = 3; p = parpool('local',numWorkers); n = numpartitions(ds,p);parforii = 1:n subds =分区(ds,n,ii);尽管hasdata(subds) data = read(subds);endend

输入参数

全部收缩

输入数据存储。您可以使用数据存储function to create a datastore object from your data.

分区数,指定为正整数。

If you specify a number of partitions that is not a numerical factor of the number of files in the datastore,partitionwill place each of the remaining observations in the existing partitions, starting with the first partition.

包含额外观察的现有分区数量等于将数据存储中的文件数除以分区数时获得的剩余数量。例如,如果您的数据存储对象包含23个您希望将其分区为3个部分的文件,则是前两个分区partition创建将包含8个文件,最后一个分区将包含7个文件。

例子:3

Data Types:双倍的

Index, specified as a positive integer.

例子:1

Data Types:双倍的

文件名,指定为字符向量或字符串标量。

的价值filename必须完全匹配Files数据存储的属性. To ensure that the file names match exactly, specifyfilenameusingds.Files{N}whereN是文件中文件的索引Filesproperty. For example,ds.files {3}指定数据存储中的第三个文件ds.

例子:ds.files {3}

例子:'file1.csv'

例子:'../dir/data/file1.csv'

例子:'hdfs:// myserver:7867/data/file1.txt'

Data Types:char

Output Arguments

全部收缩

输出数据存储。输出数据存储与输入数据存储相同ds.

Extended Capabilities

See Also

|

Topics

在R2015a中引入