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

1 次查看(过去 30 天)
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)];

回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by