How to solve Too many input arguments error? Error in Fminsearch (line 200) fv(:,1) = funfcn(x,varargin{:});

조회 수: 2 (최근 30일)
Hello,
I am doing the modelling and I am trying to find the best fit parameter with mini errors.
the experimental data is MSM, which has 6 coloums indicating 6 different measurements.
I would like to use loop to find the fits for those 6 models.
Here is my code
%% minimization / parameter estimation
% specify function handle to function vpe
fh=cell(6,1);
global pesmin
global pelmin
global Vsmin
global Vlmin
pesmin = rand(2,6); % estimated parameter
Vsmin= rand(1,6); % error
for n=1:6; %function handle
fh{n}= @(pes)vpe(pes(:,n),p,MSM(:,n),erps(:,n),n);
end
for n=1:6; % search for the mini error
[pesmin(:,n),Vsmin(n)] = fminsearch(fh{n},reshape(pesmin(:,n),[2,1]));
end
this loop can only run once. as n=2 or >2, the error comes out. the error shows Index at position 2 is out of range of the array (cannot exceed 1). I really did not get where is the position 2. what does it mean position 2 is out of range of the array.
for n=1:c/2; % search for the mini error
[pesmin(:,n),Vsmin(n)] = fminsearch(fh{n},reshape(pesmin(:,n),[2,1]));
end
Besides, it also shows
  댓글 수: 3
Walter Roberson
Walter Roberson 2020년 2월 13일
pes(:,n)
pes does not exist in the code you posted, so we do not know how large it is.
Likewise for MSM and erps.
feihong xu
feihong xu 2020년 2월 13일
pes is 2x6 matrix. p is 25x1. MSM is 25x6. erps is 25 x6.
I guess the error is from the function handle. I wanna pes changes as a colomun 2x1 since pes is 2x6.
fh{n}= @(pes)vpe(pes(:,n),p,MSM(:,n),erps(:,n),n);
But this code does not work
fh{n}= @(pes(:,n))vpe(pes(:,n),p,MSM(:,n),erps(:,n),n);

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2020년 2월 13일
편집: Matt J 2020년 2월 13일
This fh handles should be,
fh{n}= @(x)vpe(x,p,MSM(:,n),erps(:,n),n);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Filter Banks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by