Main Content


Class: matlab.compiler.mlspark.RDD
Package: matlab.compiler.mlspark

Aggregate elements of each partition and the subsequent results for all partitions


result = fold(obj,zeroValue,func)


result = fold(obj,zeroValue,func) aggregates the elements of each partition in obj and the subsequent results for all the partitions, using an associative function func and a neutral “zero value” represented by zeroValue.

Input Arguments

expand all

An input RDD, specified as a RDD object.

A neutral “zero value”, specified as a cell array of numbers.

Data Types: cell

A function for the folding action, specified as a function handle.

Data Types: function_handle

Output Arguments

expand all

Result of the folding action, returned as a scalar.


expand all

%% Connect to Spark
sparkProp = containers.Map({'spark.executor.cores'}, {'1'});
conf = matlab.compiler.mlspark.SparkConf('AppName','myApp', ...
sc = matlab.compiler.mlspark.SparkContext(conf);

%% fold
foldVal = sc.parallelize({1, 2, 3, 4, 5}, 1).fold(10, @(x,y)(x+y));

Version History

Introduced in R2016b