Main Content

remove

ValueStore オブジェクトまたは FileStore オブジェクトからエントリを削除する

R2022a 以降

説明

remove(store,keySet) は、キー keySet での指定どおり、キーと値のペアまたはキーとファイルのペアを ValueStore オブジェクトまたは FileStore オブジェクトの store から削除します。

すべて折りたたむ

ワーカー上でシミュレーションを実行し、クライアント上でジョブのデータ ストレージを取得します。データ ストレージは、キーと値のエントリをもつ ValueStore オブジェクトです。このオブジェクトから、対応するキーでの指定どおりにエントリを削除します。

次のシミュレーションでは、乱数行列の逆行列を求め、結果を ValueStore オブジェクトに保存します。

type workerInvCode
function workerInvCode(models)
% Get the ValueStore of the current job
store = getCurrentValueStore;
for i = 1:numel(models)
    % Store simulation results in the ValueStore object
    pause(1);
    key = strcat("result_",num2str(i));
    store(key) = inv(rand(models(i)));
end
end

既定のクラスター プロファイルを使用して、ワーカー上でバッチ ジョブを実行します。

models = [4,8,32,20];
c = parcluster;
job = batch(c,@workerInvCode,0,{models});
wait(job);

クライアント上の ValueStore オブジェクトを取得します。オブジェクトのキーを表示します。

store = job.ValueStore;
keys(store)
ans = 4×1 string
    "result_1"
    "result_2"
    "result_3"
    "result_4"

キー "result_1""result_4" で指定された複数のエントリをオブジェクトから削除します。

remove(store,["result_1","result_4"]);

また、構文 store(key) = [] を使用してエントリを削除することもできます。キー "result_3" で指定されたエントリをオブジェクトから削除します。

store("result_3") = [];

更新後のオブジェクトのキーを表示します。

keys(store)
ans = 
"result_2"

プロセス ワーカーの並列プール上でシミュレーションを実行し、クライアント上のファイル ストレージを取得します。ファイル ストレージは、キーとファイルのエントリをもつ FileStore オブジェクトです。このオブジェクトから、対応するキーでの指定どおりにエントリを削除します。

次のシミュレーションでは、乱数行列の平均と標準偏差を求め、結果を FileStore オブジェクトに保存します。

type workerStatsCode
function workerStatsCode(models)
% Get the FileStore of the current job
store = getCurrentFileStore;
for i = 1:numel(models)
    % Compute the average and standard deviation of random matrices
    A = rand(models(i));
    M = mean(A);
    S = std(A);
    % Save simulation results in temporary files
    sourceTempFile = strcat(tempname("C:\myTempFolder"),".mat");
    save(sourceTempFile,"M","S");
    % Copy files to FileStore object as key-file pairs
    key = strcat("result_",num2str(i));
    copyFileToStore(store,sourceTempFile,key);
end
end

プロセス ワーカーの並列プールを起動します。

pool = parpool('Processes');
Starting parallel pool (parpool) using the 'Processes' profile ...
Connected to the parallel pool (number of workers: 6).

このプールの FileStore を取得します。

store = pool.FileStore;

プール上でシミュレーションを実行します。

models = [4,8,32,20];
future = parfeval(@workerStatsCode,0,models);
wait(future);

FileStore オブジェクトのキーを表示します。

keys(store)
ans = 4×1 string
    "result_1"
    "result_2"
    "result_3"
    "result_4"

キー "result_1""result_2" で指定されたキーとファイルのエントリをオブジェクトから削除します。更新後のオブジェクトのキーを表示します。

remove(store,["result_1","result_2"]);
keys(store)
ans = 2×1 string
    "result_3"
    "result_4"

入力引数

すべて折りたたむ

MATLAB クライアントとワーカーで共有されるデータ ストレージまたはファイル ストレージ。ValueStore オブジェクトまたは FileStore オブジェクトとして指定します。

削除するエントリのキー。文字ベクトル、string スカラー、string 配列、もしくは文字ベクトルまたは string の cell 配列として指定します。

ヒント

  • ValueStore オブジェクトの場合は、構文 store(key) = [] を使用して、key で指定された 1 つのキーと値のエントリのみを削除することもできます。

バージョン履歴

R2022a で導入