How can I create a matrix with a function instead of multiplication
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
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')
1 Comment
Mohammad Abouali
on 17 Oct 2014
Edited: Mohammad Abouali
on 17 Oct 2014
It needs a transpose at the end or
M = bsxfun(F,x',y)
See Also
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!