1
votes

I'm encountering the following Matlab error:

??? Input argument "Va4" is undefined.

Error in ==>
sym.matlabFunction>makeFhandle/@(Va1,Va4,Vm1,Vm4)reshape([cos(conj(Va1)-conj(Va4)).*conj(Vm1).*conj(Vm4).*(6.25e2./7.2e1)+Vm1.*Vm4.*cos(Va1-Va4).*(6.25e2./7.2e1),sin(conj(Va1)-conj(Va4)).*conj(Vm1).*conj(Vm4).*(6.25e2./7.2e1)+Vm1.*Vm4.*sin(Va1-Va4).*(6.25e2./7.2e1),Vm4.*sin(Va1-Va4).*(6.25e2./7.2e1)+sin(conj(Va1)-conj(Va4)).*conj(Vm4).*(6.25e2./7.2e1),Vm1.*(6.25e2./3.6e1)+conj(Vm1).*(6.25e2./3.6e1)-Vm4.*cos(Va1-Va4).*(6.25e2./7.2e1)-cos(conj(Va1)-conj(Va4)).*conj(Vm4).*(6.25e2./7.2e1)],[2,2])

I'm trying to evaluate an anonymous function, a 2x2 matrix, at a point as follows

J = @(Va1,Va4,Vm1,Vm4) reshape( ...
    [cos(conj(Va1)-conj(Va4)).*conj(Vm1).*conj(Vm4).*(6.25e2./7.2e1)+Vm1.*Vm4.*cos(Va1-Va4).*(6.25e2./7.2e1),...
    sin(conj(Va1)-conj(Va4)).*conj(Vm1).*conj(Vm4).*(6.25e2./7.2e1)+Vm1.*Vm4.*sin(Va1-Va4).*(6.25e2./7.2e1),...
    Vm4.*sin(Va1-Va4).*(6.25e2./7.2e1)+sin(conj(Va1)-conj(Va4)).*conj(Vm4).*(6.25e2./7.2e1),...
    Vm1.*(6.25e2./3.6e1)+conj(Vm1).*(6.25e2./3.6e1)-Vm4.*cos(Va1-Va4).*(6.25e2./7.2e1)-cos(conj(Va1)-conj(Va4)).*conj(Vm4).*(6.25e2./7.2e1)],...
    [2,2]);

arrayfun(J, [0,0,1,1] ,  'UniformOutput', false)

Any idea what's going wrong?


EDIT: I should have mentioned that the function J is defined from some other function, so I am unable to provide the inputs as separate arguments. I have attempted to pass the input as a cell as: arrayfun(J, {0,0,1,1} , 'UniformOutput', false); but I run into the following error

??? Undefined function or method 'conj' for input arguments of type 'cell'.

EDIT #2: Solved by Nemesis below, we need to pass the cell input, A = {0,0,1,1} into arrayfun using A{:}.

1

1 Answers

1
votes

Check the documentation of arrayfun.

[B1,...,Bm] = arrayfun(func,A1,...,An,Name,Value)

Each input parameter is a single argument. Since you pass your four input parameters as array

[0,0,1,1]

this is only treated as one argument. Just rewrite your call to the anonymous function to

arrayfun(J, 0, 0, 1, 1,  'UniformOutput', false)

resolves the issue. You can now make your code more parallel using e.g.

arrayfun(J, [0 1 1],[0 0 1],[1 0 1],[1 1 1] ,  'UniformOutput', false)

ans = 

    [2x2 double]    [2x2 double]    [2x2 double]

which will use the function J on all [0,0,1,1], [1,0,0,1] and [1,1,1,1].