Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

ValueIterator

An iterator over intermediate values for use with mapreduce

Description

The mapreduce function automatically creates a ValueIterator object during execution and uses it to store the values associated with each unique intermediate key added by the map function. Although you never need to explicitly create a ValueIterator object to use mapreduce, you do need to interact with this object in the reduce function. Use the hasnext and getnext object functions to retrieve the values associated with each unique key in the intermediate KeyValueStore object.

Creation

The mapreduce function automatically creates ValueIterator objects during execution.

Properties

expand all

This property is read-only.

Intermediate key, specified as a numeric scalar or character vector. Key is one of the unique keys added by a map function. All the values in the ValueIterator object are associated with this key.

Object Functions

hasnextDetermine if ValueIterator has one or more values available
getnextGet next value from ValueIterator

Examples

expand all

Use the hasnext and getnext functions in a while loop within the reduce function to iteratively get values from the ValueIterator. For example,

function MeanDistReduceFun(sumLenKey, sumLenIter, outKVStore)
    sumLen = [0, 0];
    while hasnext(sumLenIter)
        sumLen = sumLen + getnext(sumLenIter);
    end
    add(outKVStore, 'Mean', sumLen(1)/sumLen(2));
end

Always call hasnext before getnext to confirm availability of a value. mapreduce returns an error if you call getnext with no remaining values in the ValueIterator.

Introduced in R2014b

Was this topic helpful?