How can I create a matrix with a function instead of multiplication

1 view (last 30 days)
Hi there,
Lets say I have a Function: F(x,y)
Data: x = { x1,x2 … ,xn } y = { y1,y2 … ,yn }
How can I efficiently create the matrix M =
[ F(x1,y1) , F(x1,y2) , … , F(x1,yn);
F(x2,y1) , F(x2,y2) , , F(x2,yn);
F(xn,y1) , F(xn,y2) , , F(xn,yn)];

Answers (1)

the cyclist
the cyclist on 16 Oct 2014
Edited: the cyclist on 16 Oct 2014
x = [1,2,3];
y = [4,5,6];
F = @(X,Y) X .* Y.^2;
M = bsxfun(F,x,y')

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!