remove
说明
示例
对工作单元运行仿真并在客户端上检索作业的数据存储。数据存储是一个具有键值条目的 ValueStore 对象。按照相应键的指定,从此对象中删除条目。
以下仿真寻找随机矩阵的逆并将结果存储在 ValueStore 对象中。
type workerInvCodefunction 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 workerStatsCodefunction 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 对象。
要删除的条目的键,指定为字符向量、字符串标量、字符串数组、或者字符向量或字符串的元胞数组。
提示
对于
ValueStore对象,您还可以使用语法store(key) = []仅删除key指定的一个键值条目。
版本历史记录
在 R2022a 中推出
另请参阅
ValueStore | FileStore | isKey | keys | put | get | copyFileToStore | copyFileFromStore
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)