numpartitions
説明
例
信号データストアの既定の数のパーツへの分割
MATLAB® に含まれる信号の例へのファイル パスを指定します。指定したフォルダーを示す信号データストアを作成します。
folder = fullfile(matlabroot,'toolbox','matlab','audiovideo'); sds = signalDatastore(folder,'SampleRateVariableName','Fs');
信号データストアの区画の既定の数を取得します。
n = numpartitions(sds)
n = 7
データストアを既定の数の区画に分割し、4 番目の区画に対応するデータストアを返します。
subsds = partition(sds,n,4);
関数extractAfter
を使用して、4 番目の区画に対応するデータストアに含まれるファイルの名前を表示します。
fName = extractAfter(subsds.Files,'audiovideo\')
fName = 1x1 cell array
{0x0 char}
4 番目の区画に対応するデータストアの信号に関するデータと情報を読み取ります。info
からサンプル レートを抽出し、信号を元のサンプル レートの半分にリサンプリングします。元の信号とリサンプリングした信号をプロットします。
while hasdata(subsds) [data,info] = read(subsds); fs = info.SampleRate; f_res = 0.5*fs; ts = (0:length(data)-1)/fs; data_res = resample(data,1,2); t_res = (0:length(data_res)-1)/f_res; plot(ts,data,t_res,data_res,':') xlabel('Time (s)') ylabel('Signal') legend('Original','Resampled','Location','NorthWest') end
並列アクセスのための信号データストアの分割
MATLAB® に付属する信号の例が格納されているディレクトリへのパスを指定します。
folder = fullfile(matlabroot,'toolbox','matlab','audiovideo');
指定したフォルダーを示す信号データストアを作成します。
sds = signalDatastore(folder);
現在の並列プールについて、並列処理のための妥当な区画数に関する推定を返します。
pool = gcp;
Starting parallel pool (parpool) using the 'local' profile ... Connected to the parallel pool (number of workers: 6).
n = numpartitions(sds,pool)
n = 7
信号データストアを分割し、各区画の信号データを読み取ります。
parfor ii = 1:n subds = partition(sds,n,ii); while hasdata(subds) data = read(subds); end end
入力引数
sds
— 信号データストア
signalDatastore
オブジェクト
信号データストア。signalDatastore
オブジェクトとして指定します。
pool
— 並列プール
並列プール オブジェクト
並列プール。並列プール オブジェクトとして指定します。
出力引数
n
— 分割数
正の整数
データストア アクセスが並列化される区画の数。既定では、区画の数は min(Nobservations , 3Nworkers) です。このとき、次のようになります。
Nobservations は、データストアのファイルの数(ファイル データの場合) またはデータストアのメンバーの数 (インメモリ データの場合) です。
Nworkers は、プールのワーカーの数です。
バージョン履歴
R2020a で導入
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)