From: Adrian gavrila on
I am using Fminsearch and as output I use outfun.The problem I have is that I cannot save the resulting values for variables.It only saves in outfun1 the values of the last iteration and also for plotting.I know that I can use optimValues.field but I cannot acces the value of the evaluation count. Is there a solution to this.?

thank you

Please help.

fminsearch----------------

options =optimset('Display','iter','MaxFunEvals',300,'OutputFcn',@outfun)
%-----calling for outfun --- ,'OutputFcn',@outfun
[y,fval,exitflag,output]=fminsearchbnd(@(w_tooth) marcu(w_tooth),dim,LB,UB,options);

------------------outfun
function stop = outfun(T,optimValues,state)
global I1 I2 I3 T fluxA fluxB fluxC theta I2q
stop=[];
historyT = [];
historyfval=[];
counti=[];
i=0;
if state== 'iter'
hold on
i=i+1;
torques(i)=T;
count(i)=i;
% Concatenate current point and objective function
% value with history. x must be a row vector.
historyfval = [historyfval; optimValues.funcCount];
historyT = [historyT;T];
%plot(iter,history.fval,'.');
%plot(iter,history.fval,'.');
save('outfun1')
plot(historyfval,torques,'.')
hold off
end
end
From: Steven Lord on

"Adrian gavrila" <adig_coool(a)yahoo.com> wrote in message
news:hrmkpc$mrn$1(a)fred.mathworks.com...
>I am using Fminsearch and as output I use outfun.The problem I have is that
>I cannot save the resulting values for variables.It only saves in outfun1
>the values of the last iteration and also for plotting.I know that I can
>use optimValues.field but I cannot acces the value of the evaluation count.
>Is there a solution to this.?

Use persistent variables or write your output function as a nested function.
You should also not do ...

*snip*

> if state== 'iter'

this, as if state were a string that did not contain 4 characters or a
scalar, this would error. Instead I would use SWITCH or STRCMP to handle
the different 'state' inputs.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


 | 
Pages: 1
Prev: distance between points
Next: mcc and nnet-toolbox