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)];
0 个评论
回答(1 个)
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')
1 个评论
Mohammad Abouali
2014-10-17
编辑:Mohammad Abouali
2014-10-17
It needs a transpose at the end or
M = bsxfun(F,x',y)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!