Error using fcnchk (line 106) FUN must be a function, a valid string expression, or an inline function object. Error in fminsearch (line 162) funfcn = fcnchk(fun​fcn,length​(varargin)​);

17 次查看(过去 30 天)
Hi,i'm new,it's urgent!
i have this problem: i created a function
function [ q ] = minimizza_x_tau(tc);
load('datinuovi.mat')
fsamp=50;
N=length(Datitermocoppia) ;
t=[0:1/fsamp:N/fsamp-1/fsamp];
salto=max(Datitermocoppia)-min(Datitermocoppia);
y=salto.*(1-exp(-t./tc));
y2=rot90(y);
diffe=(Datitermocoppia-y2).^2;
q=sum(diffe);
end
when i call the function from the script for example with
tc=2;
[taunew]=minimizza_x_tau(tc);
it works, but it is not i have to do.
i have to do a minimization as it:
tc=2;
[q]=fminsearch(minimizza_x_tau(tc),0.24);
If i do that it says me ERRORS above.
you know why? i don't know if put tc=2 is right i put them for example.
thank you

回答(1 个)

Matt J
Matt J 2016-6-1
You need to pass a handle to the objective function
[q]=fminsearch(@minimizza_x_tau,0.24);

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by