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

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)];

Risposte (1)

x = [1,2,3];
y = [4,5,6];
F = @(X,Y) X .* Y.^2;
M = bsxfun(F,x,y')

Categorie

Richiesto:

il 16 Ott 2014

Modificato:

il 17 Ott 2014

Community Treasure Hunt

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

Start Hunting!

Translated by