Home > data-access > supporting_files > func_map.m

func_map

PURPOSE ^

Basically a glorified FOREACH.

SYNOPSIS ^

function results = func_map ( F, input )

DESCRIPTION ^

Basically a glorified FOREACH.
   func_map(FUNCTION, ARRAY)
       Applies FUNCTION to each row of ARRAY, returning
       the results in an array with the same number of rows
       as ARRAY, and as many columns as F returns.
      
   FUNCTION must return the same number of values for any input value.
   FUNCTION should take one argument, which will be a one-row array
   containing one row from the input ARRAY.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function results = func_map ( F, input )
0002 %Basically a glorified FOREACH.
0003 %   func_map(FUNCTION, ARRAY)
0004 %       Applies FUNCTION to each row of ARRAY, returning
0005 %       the results in an array with the same number of rows
0006 %       as ARRAY, and as many columns as F returns.
0007 %
0008 %   FUNCTION must return the same number of values for any input value.
0009 %   FUNCTION should take one argument, which will be a one-row array
0010 %   containing one row from the input ARRAY.
0011 
0012 in_dims = size(input);
0013 
0014 if length(input) < 1
0015     results = input;
0016     return
0017 end
0018 
0019 % For each row in INPUT...
0020 for idx = 1:in_dims(1)
0021     results(idx, :) = F(input(idx, :));
0022 end
0023 
0024

Generated on Tue 23-May-2017 20:00:55 by m2html © 2005