subset
Create subset of datastore or file-set
Syntax
Description
subds = subset(
returns a subset containing files corresponding tods
,indices
)indices
. The subsetsubds
is of the same type as the input.
if the input
ds
is a datastore, then the outputoutds
is a datastore of the same type.if the input
ds
is aDsFileSet
,FileSet
, orBlockedFileSet
object, then the outputsubds
is also, respectively, aDsFileSet
,FileSet
, orBlockedFileSet
object.
Examples
Create Subset ofImageDatastore
Make an image datastore object and then create a subset of that image datastore.
Create an image datastoreimds
for all the image files in a sample folder. Then, display theFiles
property ofimds
.
folders = fullfile(matlabroot,'toolbox','matlab',{'demos','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' }
Create a subset datastoresubimds
包含第一个四files ofimds
and examine theFiles
property 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' }
Create Subset Datastore with Randomly Selected Files
Make an image datastore, and then create subset datastore containing only a specified percentage of files, randomly selected from the original datastore.
CreateimageDatastore
for all the image files in a sample folder and display theFiles
property. This datastore contains 8 files.
folders = fullfile(matlabroot,'toolbox','matlab',{'demos','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' }
Create a set of indices that represents randomly selected subset containing60%
of the files.
nFiles = length(imds.Files); RandIndices = randperm(nFiles); nSixtyPercent = round(0.6*nFiles); indices = RandIndices(1:nSixtyPercent)
indices = 8 6 4 5 1
Create a subset datastoresubmids
usingindices
and examine itsFiles
property.
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
ds
—Input datastore or file-set
ImageDatastore
|DsFileSet
|FileSet
|BlockedFileSet
Input datastore or file-set, specified asImageDatastore
,DsFileSet
,FileSet
,BlockedFileSet
object.
To create an
ImageDatastore
object, useimageDatastore
.To create a
DsFileSet
object, usematlab.io.datastore.DsFileSet
.To create a
FileSet
object, usematlab.io.datastore.FileSet
.To create a
BlockedFileSet
object, usematlab.io.datastore.BlockedFileSet
.
indices
—Indices of files to include in subset
vector of indices|logical vector
Indices of files to include in subset, specified as a vector of indices or a logical vector.
The vector of indices must contain the indices of files to include in the subset
subds
.The logical vector must be of the same length as the number of files in the input
ds
. Thesubset
method creates a subsetsubds
containing files corresponding to the elements in the logical vector that have a value oftrue
.
Elements ofindices
must be unique.
Data Types:double
|logical
Extended Capabilities
Thread-Based Environment
Run code in the background using MATLAB®backgroundPool
or accelerate code with Parallel Computing Toolbox™ThreadPool
.
Usage notes and limitations:
在一个线程环境,您可以使用
subset
only with the following datastores:ImageDatastore
objectsCombinedDatastore
orTransformedDatastore
objects you create fromImageDatastore
objects by usingcombine
ortransform
You can use
subset
with other datastores if you have Parallel Computing Toolbox™. To do so, run the function using a process-backed parallel pool instead of usingbackgroundPool
orThreadPool
(use eitherProcessPool
orClusterPool
).
For more information, seeRun MATLAB Functions in Thread-Based Environment.
Version History
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi 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)