Referring to https://www.mathworks.com/matlabcentral/answers/161876-matlab-coder-and-fminsearch-what-implementation-strategy
I didn't understand how to define the function using presistant values, what I did is this function p=fun(x,D,y,lampda,h)
persistent D_saved;
persistent y_saved;
persistent lampda_saved;
persistent h_saved;
D_saved=D;
y_saved=y;
h_saved=h;
lampda_saved=lampda;
p=(lampda_saved*norm(h_saved-x,1))+norm((D_saved*x)-y_saved,2);
and when using fminsearch
problem.options = optimset('Display','off','TolX',ep,'TolFun',ep);
problem.solver = 'fminsearch';
problem.objective = fun(x,D,y,lampda,h);
where h, D, and y are variables and x is to be optimised when I run this I get an error "Undefined function or variable 'x'" ?

Réponses (0)

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by