MatlabFunction error: Argument 'vars' failed validation isVars.

조회 수: 5 (최근 30일)
Lu zhang
Lu zhang 2016년 11월 19일
답변: Walter Roberson 2016년 11월 20일
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에서 Function Creation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by