Main Content


Add key-value pairs to ValueStore object

Since R2022a



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.


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
    key = strcat("result_",num2str(i));
    store(key) = inv(rand(models(i)));

Run a batch job on workers using the default cluster profile.

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

Retrieve the ValueStore object on the client. Show the keys of the object.

store = job.ValueStore;
ans = 4×1 string

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.

ans = 5×1 string

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.


  • 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

| | | |