Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Problem 651. Functional inputs

Created by Alex Feinman

Return an n-dimensional array whose elements are the results of a function over a set of vectors.

The (i,j,k, ...n)th element of the output matrix is the results of executing the function on the ith element of the first vector, jth element of the second, and so forth. The function will be passed in, accepts n arguments, and returns a single number.

For example, if the function is:

    minus12 = @(a) a(1)-a(2);

and the inputs are:

    as = [1 3 5 7];
    bs = [0 1 2 3 4];

then the output would be:

    >> gridit(minus12, as, bs)
    ans =
           1  0 -1 -2 -3
           3  2  1  0 -1
           5  4  3  2  1
           7  6  5  4  3

Tags

Problem Group

Solution Statistics

11 correct solutions 10 incorrect solutions
Last solution submitted on Apr 09, 2014

Problem Comments