主要内容

subset

创建数据存储或文件集的子集

Description

example

subds =子集(ds,indices)returns a subset containing files corresponding toindices。子集subds与输入的类型相同。

  • if the inputds是数据存储,然后是输出outdsis a datastore of the same type.

  • if the inputdsis aDsFileSet,文件集, orBlockedFileSetobject, then the outputsubds也分别是DsFileSet,文件集, orBlockedFileSet目的。

Examples

collapse all

制作图像数据存储对象,然后创建该图像数据存储的子集。

创造an image datastoreimdsfor all the image files in a sample folder. Then, display theFilesproperty ofimds

folders = fullfile(matlabroot,'工具箱','matlab',{“演示”,'imagesci'}); exts = {'.jpg','.png','.tif'}; imds = imageDatastore(folders,“ Labelsource”,'foldernames',“ fileextensions',exts); imds.Files
ans = 8×1 cell array {'...\matlab\toolbox\matlab\demos\cloudCombined.jpg'} {'...\matlab\toolbox\matlab\demos\example.tif' } {'...\matlab\toolbox\matlab\demos\landOcean.jpg' } {'...\matlab\toolbox\matlab\demos\ngc6543a.jpg' } {'...\matlab\toolbox\matlab\demos\street1.jpg' } {'...\matlab\toolbox\matlab\demos\street2.jpg' } {'...\matlab\toolbox\matlab\imagesci\corn.tif' } {'...\matlab\toolbox\matlab\imagesci\peppers.png' }

创造a subset datastoresubimds包含第一个四files ofimdsand examine theFilesproperty ofsubimds

indices = 1:4; subimds = subset(imds,indices); subimds.Files
ans = 4×1 cell array {'...\matlab\toolbox\matlab\demos\cloudCombined.jpg'} {'...\matlab\toolbox\matlab\demos\example.tif' } {'...\matlab\toolbox\matlab\demos\landOcean.jpg' } {'...\matlab\toolbox\matlab\demos\ngc6543a.jpg' }

Make an image datastore, and then create subset datastore containing only a specified percentage of files, randomly selected from the original datastore.

创造成像for all the image files in a sample folder and display theFilesproperty. This datastore contains 8 files.

folders = fullfile(matlabroot,'工具箱','matlab',{“演示”,'imagesci'}); exts = {'.jpg','.png','.tif'}; imds = imageDatastore(folders,“ Labelsource”,'foldernames',“ fileextensions',exts); imds.Files
ans = 8×1 cell array {'...\matlab\toolbox\matlab\demos\cloudCombined.jpg'} {'...\matlab\toolbox\matlab\demos\example.tif' } {'...\matlab\toolbox\matlab\demos\landOcean.jpg' } {'...\matlab\toolbox\matlab\demos\ngc6543a.jpg' } {'...\matlab\toolbox\matlab\demos\street1.jpg' } {'...\matlab\toolbox\matlab\demos\street2.jpg' } {'...\matlab\toolbox\matlab\imagesci\corn.tif' } {'...\matlab\toolbox\matlab\imagesci\peppers.png' }

创造a set of indices that represents randomly selected subset containing60%of the files.

nfiles =长度(imds.files);randindices = randperm(nfiles);nsixtypercent =圆形(0.6*nfiles);indices = randindices(1:nsixtypercent)
indices = 8 6 4 5 1

创造a subset datastore提出usingindicesand examine itsFilesproperty.

subimds = subset(imds,indices); subimds.Files
ans = 5×1 cell array {'...\matlab\toolbox\matlab\imagesci\peppers.png' } {'...\matlab\toolbox\matlab\demos\street2.jpg' } {'...\matlab\toolbox\matlab\demos\ngc6543a.jpg' } {'...\matlab\toolbox\matlab\demos\street1.jpg' } {'...\matlab\toolbox\matlab\demos\cloudCombined.jpg'}

Input Arguments

collapse all

输入数据存储或文件集, specified asImageDatastore,DsFileSet,文件集,BlockedFileSet目的。

Indices of files to include in subset, specified as a vector of indices or a logical vector.

  • 这指数向量must contain the indices of files to include in the subsetsubds

  • 这logical vector must be of the same length as the number of files in the inputds。这subsetmethod creates a subsetsubds包含对应于具有逻辑向量元素的文件,该元素的值真的

Elements ofindicesmust be unique.

Data Types:double|logical

Extended Capabilities

Introduced in R2019a