put - Add key-value pairs to ValueStore object - MATLAB (original) (raw)
Main Content
Add key-value pairs to ValueStore
object
Since R2022a
Syntax
Description
put([store](#mw%5F71283661-4e0c-448f-b620-9e40c89dc529),[keySet](#mw%5F6f701d64-e639-4a61-9f82-5d4745428987),[valueSet](#mw%5F6c0e28fe-c09f-40d2-a986-0cd6ed22e87e))
adds key-value pairs to the ValueStore
object store
.valueSet
is a cell array of values that is added tostore
using the corresponding keys keySet
. If the keys already exist in store
, then put
replaces the values for the specified keys.
Examples
Run a simulation on workers and retrieve the data storage of the job on a client. The data storage is a ValueStore
object with key-value entries. Add entries to this object as specified by their corresponding keys.
The following simulation finds the inverse of random matrices and stores the results in the ValueStore
object.
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
Run a batch job on workers using the default cluster profile.
models = [4,8,32,20]; c = parcluster; job = batch(c,@workerInvCode,0,{models}); wait(job);
Retrieve the ValueStore
object on the client. Show the keys of the object.
store = job.ValueStore; keys(store)
ans = 4×1 string "result_1" "result_2" "result_3" "result_4"
Add multiple key-value entries as specified by the keys "matrix_2"
and "result_2"
to the object. Show the keys of the updated object.
put(store,["matrix_2","result_2"],{rand(4),inv(rand(4))}) keys(store)
ans = 5×1 string "matrix_2" "result_1" "result_2" "result_3" "result_4"
Input Arguments
Data storage shared by MATLAB clients and workers, specified as a ValueStore
object.
Keys to add, specified as a character vector, string scalar, string array, or cell array of character vectors or strings. keySet
andvalueSet
must have the same number of elements.
Values to add, specified as a cell array. keySet
andvalueSet
must have the same number of elements.
Tips
- To add only one key-value entry as specified by
key
, you can also use the syntaxstore(key) = value
.
Version History
Introduced in R2022a