subset
データ ストアまたはファイル セットのサブセットを作成
説明
例
ImageDatastore
のサブセットを作成
イメージの datastore オブジェクトを作成してから、そのイメージ データ ストアのサブセットを作成します。
サンプル フォルダー内のすべてのイメージ ファイル用のイメージ データ ストア imds
を作成します。次に、imds
の 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' }
imds
の最初の 4 つのファイルを含むサブセット データ ストア subimds
を作成し、subimds
の Files
プロパティを確認します。
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' }
ランダムに選択したファイルを含むサブセット データ ストアを作成
イメージ データ ストアを作成してから、元のデータ ストアから指定の割合でランダムに選択されたファイルのみを含むサブセット データ ストアを作成します。
サンプル フォルダー内のすべてのイメージ ファイル用に imageDatastore
を作成し、Files
プロパティを表示します。このデータ ストアには 8 つのファイルが含まれています。
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' }
ファイルの 60%
を含み、ランダムに選択されたサブセットを表すインデックスのセットを作成します。
nFiles = length(imds.Files); RandIndices = randperm(nFiles); nSixtyPercent = round(0.6*nFiles); indices = RandIndices(1:nSixtyPercent)
indices = 8 6 4 5 1
indices
を使用してサブセット データ ストア submids
を作成し、その Files
プロパティを確認します。
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'}
入力引数
ds
— 入力のデータ ストアまたはファイル セット
ImageDatastore
| DsFileSet
| FileSet
| BlockedFileSet
入力のデータストアまたはファイル セット。ImageDatastore
、DsFileSet
、FileSet
または BlockedFileSet
オブジェクトとして指定します。
ImageDatastore
オブジェクトを作成するには、imageDatastore
を使用。DsFileSet
オブジェクトを作成するには、matlab.io.datastore.DsFileSet
を使用。FileSet
オブジェクトを作成するには、matlab.io.datastore.FileSet
を使用。BlockedFileSet
オブジェクトを作成するには、matlab.io.datastore.BlockedFileSet
を使用。
indices
— サブセットに含めるファイルのインデックス
インデックスのベクトル | logical ベクトル
サブセットに含めるファイルのインデックス。インデックスのベクトルまたは logical ベクトルとして指定します。
インデックスのベクトルには、サブセット
subds
に含めるファイルのインデックスを含めなければならない。logical ベクトルの長さは、入力
ds
のファイル数と同じでなければならない。subset
メソッドは、値true
をもつ logical ベクトルの要素に対応するファイルを含むサブセットsubds
を作成します。
indices
の要素は一意でなければなりません。
データ型: double
| logical
拡張機能
スレッドベースの環境
MATLAB® backgroundPool
を使用してバックグラウンドでコードを実行するか、Parallel Computing Toolbox™ のThreadPool
を使用してコードを高速化します。
使用上の注意事項および制限事項:
スレッドベースの環境では、次のデータストアでのみ
subset
を使用できます。ImageDatastore
オブジェクトcombine
またはtransform
を使用してImageDatastore
オブジェクトから作成するCombinedDatastore
またはTransformedDatastore
オブジェクト
Parallel Computing Toolbox™ がある場合は、他のデータストアで
subset
を使用できます。これを行うには、backgroundPool
またはThreadPool
を使用する代わりに、プロセスベースの並列プールを使用して関数を実行します (ProcessPool
またはClusterPool
を使用します)。
詳細については、Run MATLAB Functions in Thread-Based Environmentを参照してください。
バージョン履歴
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)