Main Content

put

Add key-value pairs to ValueStore object

Since R2022a

Description

put(store,keySet,valueSet) adds key-value pairs to the ValueStore object store. valueSet is a cell array of values that is added to store using the corresponding keys keySet. If the keys already exist in store, then put replaces the values for the specified keys.

example

Examples

collapse all

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.

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

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

collapse all

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 and valueSet must have the same number of elements.

Values to add, specified as a cell array. keySet and valueSet must have the same number of elements.

Tips

  • To add only one key-value entry as specified by key, you can also use the syntax store(key) = value.

Version History

Introduced in R2022a

See Also

| | | |