Main Content


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

Reduce elements of an RDD using the specified commutative and associative function


result = reduce(obj,func)


result = reduce(obj,func) reduces the elements of obj using the specified commutative and associative function func.

Input Arguments

expand all

An input RDD, specified as a RDD object.

Commutative and associative function that will be applied to elements of the RDD.

Data Types: function_handle

Output Arguments

expand all

Reduced elements of the input RDD, 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);

%% Reduce
reduceVal = sc.parallelize({1, 2, 3, 4, 5}).reduce(@(x,y)(x+y));

Version History

Introduced in R2016b