MatlabFunction error: Argument 'vars' failed validation isVars.

2 次查看(过去 30 天)
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

回答(1 个)

Walter Roberson
Walter Roberson 2016-11-20
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.

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by