MatlabFunction error: Argument 'vars' failed validation isVars.

3 views (last 30 days)
here In my program, I calculate the symbolic gradient and evaluate them with given values.However,when I enconter a error when using the MatlabFunction. The error says
Error using sym/matlabFunction>getOptions (line 500)
Argument 'vars' failed validation isVars.
Error in sym/matlabFunction (line 100)
opts = getOptions(args);
Error in mini_dist (line 54)
matlabFunction(dfb,'file',filename,'vars',b);
The related part of my program is
[b,fun,flag] = fminunc(@cov,b0);
%dfb = gradient(fcn,b);
nT = T_z + T_e;
B = sym('B', [nT, 1]);
temp = fcn(B); %zt and et are not defined until fcn is run
v = [zt;et];
dfb = jacobian(temp,v);
currdir = [pwd filesep]; % You may need to use currdir = pwd
filename = [currdir,'gradient.m'];
matlabFunction(dfb,'file',filename,'vars',b); % Line-54 %
And the full code and data see attachment
Also, a former related question is here
Thank you for your advice

Answers (1)

Walter Roberson
Walter Roberson on 20 Nov 2016
You have
[b,fun,flag] = fminunc(@cov,b0);
so your b is numeric.
You have
matlabFunction(dfb,'file',filename,'vars',b); % Line-54 %
but your b is numeric.
You should possibly be passing in B or v rather than b.
When I tested your code before, the returned jacobian had only numeric entries and no variables; I did not test your current code. You need to think more about how your jacobian is to be used.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!