Main Content

filter

Class: matlab.compiler.mlspark.RDD
Namespace: matlab.compiler.mlspark

Return a new RDD containing only the elements that satisfy a predicate function

Syntax

result = filter(obj,func,varargin)

Description

result = filter(obj,func,varargin) applies a predicate function func to every element in obj. Elements that satisfy the criteria set by the predicate function are retained, others are discarded. A predicate function is one that returns true in a given logical function.

Input Arguments

expand all

An input RDD to be filtered, specified as a RDD object.

Predicate function, specified as a function handle. A predicate function returns true in a given logical function.

Data Types: function_handle

A variable-length input argument list representing inputs to the predicate function.

Output Arguments

expand all

An output RDD, returned as a RDD object.

Examples

expand all

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

%% filter
rdd = sc.parallelize({1, 2, 3, 4, 5});
res = rdd.filter(@(x) mod(x,2) == 0).collect();

Version History

Introduced in R2016b