Mary
Mary

Reputation: 788

??? Undefined function or variable

Why do i get the error

??? Undefined function or variable

when trying to call the following function:

    function Diff= myfun3(wk,omega)
wcalc=inv(lambda* Passetcovar)*inv(inv(tau * Passetcovar)+ PMat(i,:)'*inv(omega)*PMat(i,:))*(inv(tau * Passetcovar)*Pi+ PMat(i,:)'*inv(omega)*Q(i,:));
Diff=sum((wk-wcalc).^2);
end

All the parameters in the function are defined and correct.

I am calling this function using myfun3(wk,omega) but I get error messages such as

??? Undefined function or variable 'lambda'.

Even when lambda has been defined eslewhere.

Upvotes: 0

Views: 1728

Answers (1)

am304
am304

Reputation: 13886

lambda isn't defined in the function workspace, even if it is defined in your base workspace. Either pass it as an input to the function or define it as a global variable. See http://www.mathworks.co.uk/help/matlab/matlab_prog/share-data-between-workspaces.html for more details.

Upvotes: 2

Related Questions