forEach

Purpose

Applies a given function to each element of in an array of sets.

Syntax

A = obj.forEach(@myfun)
A = obj.forEach(@(x) myfun(x))
A = obj.forEach(@(x) x.myfun)

Description

The method forEach is an overloaded method of standard arrayfun or cellfun that applies to arrays of sets. To apply method MYFUN to all elements of the array of objects OBJ, you can use any of the following ways:

Note that forEach will not return any outputs if not asked to. Outputs can be requested as well:

[A, B, C] = obj.forEach(@myfun) If MYFUN generates all its outputs as scalars, then A, B, and C will be arrays with as many elements as there are elements in the array OBJ. If outputs generated by MYFUN have different sizes for different elements of OBJ, then you must set the "UniformOutput" option to false:

[A, B, C] = obj.forEach(@myfun, 'UniformOutput', false) In this case A, B, and C will be cell arrays, with A{i}, B{i} and C{i} containing the output of MYFUN applied to the i-th element of OBJ. In short, the forEach method works exactly as arrayfun and cellfun, hence see "help arrayfun" for a more throught description.

Input Arguments

@myfun

A handle to a function that is to be applied to each element in the array of sets for object obj.

Class: function_handle

Output Arguments

A

Array or cell array of outputs returned by function @myfun that correspond to individual outputs from the array of sets obj.

Class:

Example(s)

Example 1

Create array of 5 random polyhedra
 for i=1:5; P(i)=ExamplePoly.randVrep; end 
 For each polyhedron in the array execute the function outerApprox 
      
 B = P.forEach(@outerApprox) 
Array of 5 polyhedra.
In B we have computed the outer bounding boxes for each polyhedron in the array. It is the same results if asked
 Bnew = P.outerApprox 
Array of 5 polyhedra.

Example 2

Create two unions of polyhedra in different dimensions
 U(1) = PolyUnion([ExamplePoly.randVrep;ExamplePoly.randVrep]); 

 U(2) = PolyUnion([ExamplePoly.randVrep('d',3);ExamplePoly.randVrep('d',3)]); 
 For each polyunion in the array extract the convexity property that is computed by isConvex method.
 ts = U.forEach(@isConvex)
ts =

     0     0

The same result can be obtained by
 tn = U.isConvex 
tn =

     0     0

See Also

polyhedron, convexset


© 2003-2013 Michal Kvasnica: STU Bratislava, michal.kvasnica@stuba.sk

© 2010-2013 Martin Herceg: ETH Zurich, herceg@control.ee.ethz.ch