Main Content


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

Return a new RDD by first applying a function to all elements of an existing RDD, and then flattening the results


result = flatMap(obj,func,varargin)


result = flatMap(obj,func,varargin) returns a new RDD result by first applying a function func to all elements of obj, and then flattening the results.

Input Arguments

expand all

An input RDD on which a function is applied, specified as a RDD object.

Function to be applied to each element in the input RDD, specified as a function handle.


Data Types: function_handle

A variable-length input argument list representing inputs to the function that is being applied.

Output Arguments

expand all

An output RDD, returned as a RDD object.


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);

%% flatMap
inRDD = sc.parallelize({'A','B'});
flatRDD = inRDD.flatMap(@(x)({x,1}));
viewRes = flatRDD.collect()
Introduced in R2016b