matlab constant anonymous function returns only one value instead of an array
Posted
by
Filo
on Stack Overflow
See other posts from Stack Overflow
or by Filo
Published on 2013-10-27T09:39:22Z
Indexed on
2013/10/27
9:54 UTC
Read the original article
Hit count: 247
matlab
|anonymous-function
I've been searching the net for a couple of mornings and found nothing, hope you can help.
I have an anonymous function like this
f = @(x,y) [sin(2*pi*x).*cos(2*pi*y), cos(2*pi*x).*sin(2*pi*y)];
that needs to be evaluated on an array of points, something like
x = 0:0.1:1;
y = 0:0.1:1;
w = f(x',y');
Now, in the above example everything works fine, the result w is a 11x2 matrix with in each row the correct value f(x(i), y(i)). The problem comes when I change my function to have constant values:
f = @(x,y) [0, 1];
Now, even with array inputs like before, I only get out a 1x2 array like w = [0,1]; while of course I want to have the same structure as before, i.e. a 11x2 matrix.
I have no idea why Matlab is doing this...
© Stack Overflow or respective owner