1

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 Answer 1

1

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].

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I should have mentioned that this process needs to be done somewhat dynamically, meaning, J is defined by some other function, so I can't manually split the input argument. As a result of this I tried using: arrayfun(J, {0,0,1,1} , 'UniformOutput', false) but I ran into an error ??? Undefined function or method 'conj' for input arguments of type 'cell'.
In this case, assign your data to a cell like A = {0,0,1,1} and pass it to arrayfun by arrayfun(J, A{:} , 'UniformOutput', false).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.