fminsearch, Not enough input arguments.

1 view (last 30 days)
DK
DK on 30 Dec 2020
Answered: DK on 1 Jan 2021
Below is my code to estimate the parms1 and parms2.
Anyone can give me some helps?
Thanks!
function rresult = calibgrain(DBn_2,dateob,Tb)
dss = linspace(0.01,3,100);
ggf = linspace(0.5,5,100);
rresult = [];
for ii = 1:length(dss)
for jj = 1:length(ggf)
dsnowi = dss(ii);grfactor = ggf(jj);
startparms = [dsnowi grfactor];
%rosen = @RMSE1 RMSE1(startparms);
%fminsearch(@(prms) BER_optimise(prms(1), prms(2)),x0)
bestparms = fminsearch(@(parms) RMSE1(parms), startparms);
%bestparms = fminsearch(@RMSE1,RMSE1(startparms)); %fminsearchbnd(@(x) f(x,c),[0.3;1], [0 0],[5 5])
dsnowi = bestparms(1);
grfactor = bestparms(2);
[dsns_2,lws,btotals,phis,dsnows_y2_r1,tsnows,sds_0,kss,tsss,gds,outmelts,YEH,YEV,YEVH, YEHV,result,compaction,ritisi,stor,ro] = msnow(1,6552,DBn_2,dsnowi,grfactor);
rmsecomp = calcrmse(YEH,dateob,Tb);
rresult = [rresult ;dsnowi grfactor rmsecomp];
end % end of jj loop
end % end of ii loop
function thisrmse = RMSE1(parms)
% nest this function inside calibgrain so that it has
% access to all of calibgrain's variables.
dsnowi = parms(1);
grfactor = parms(2);
[dsns_2,lws,btotals,phis,dsnows_y2_r1,tsnows,sds_0,kss,tsss,gds,outmelts,YEH,YEV,YEVH, YEHV,result,compaction,ritisi,stor,ro] = msnow(1,6552,DBn_2,dsnowi,grfactor);
thisrmse = calcrmse(YEH,dateob,Tb);
end % end of function RMSE1
end % end of function calibgrain

Answers (2)

Alan Weiss
Alan Weiss on 30 Dec 2020
Next time please give the entire error message by copying and pasting everything in red:
Not enough input arguments.
Error in calibgrain/RMSE1 (line 30)
[dsns_2,lws,btotals,phis,dsnows_y2_r1,tsnows,sds_0,kss,tsss,gds,outmelts,YEH,YEV,YEVH,
YEHV,result,compaction,ritisi,stor,ro] = msnow(1,6552,DBn_2,dsnowi,grfactor);
Error in calibgrain>@(parms)RMSE1(parms) (line 14)
bestparms = fminsearch(@(parms) RMSE1(parms), startparms);
Error in fminsearch (line 201)
fv(:,1) = funfcn(x,varargin{:});
Error in calibgrain (line 14)
bestparms = fminsearch(@(parms) RMSE1(parms), startparms);
The error is in the msnow function, not in how you are calling fminsearch.
Alan Weiss
MATLAB mathematical toolbox documentation
  1 Comment
DK
DK on 30 Dec 2020
Thanks.
Error occurs at 200 in fminsearch
fv(:,1) = funfcn(x,varargin{:});
Not enough input arguments.
Error in calibgrain/RMSE1 (line 30)
[dsns_2,lws,btotals,phis,dsnows_y2_r1,tsnows,sds_0,kss,tsss,gds,outmelts,YEH,YEV,YEVH,
YEHV,result,compaction,ritisi,stor,ro] = msnow(1,6552,DBn_2,dsnowi,grfactor);
Error in calibgrain>@(parms)RMSE1(parms) (line 14)
bestparms = fminsearch(@(parms) RMSE1(parms), startparms);
Error in fminsearch (line 200)
fv(:,1) = funfcn(x,varargin{:});
Error in calibgrain (line 14)
bestparms = fminsearch(@(parms) RMSE1(parms), startparms);
I have tested msnow, but no other errors occured.

Sign in to comment.


DK
DK on 1 Jan 2021
I think I corrected my stupid codes. Thanks for your time!
dsnowi = 0.01; %dss(ii);
grfactor = 0.5; %ggf(jj);
startparms = [dsnowi grfactor];
%rosen = @RMSE1 RMSE1(startparms);
%fminsearch(@(prms) BER_optimise(prms(1), prms(2)),x0)
bestparms = fminsearch(@(parms) RMSE1(parms,DBn_2,dateob,Tb), startparms);
%RMSE1(parms,DBn_2,dateob,Tb)
%in another editor window, RMSE1 is defined as:
%search parameters
function thisrmse = RMSE1(parms,DBn_2,dateob,Tb)
% nest this function inside calibgrain so that it has
% access to all of calibgrain's variables.
dsnowi = parms(1);
grfactor = parms(2);
[dsns_2,lws,btotals,phis,dsnows_y2_r1,tsnows,sds_0,kss,tsss,gds,outmelts,YEH,YEV,YEVH, YEHV,result,compaction,ritisi,stor,ro] = msnow(1,6552,DBn_2,dsnowi,grfactor);
thisrmse = calcrmse(YEH,dateob,Tb);
end % end of function RMSE1

Community Treasure Hunt

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

Start Hunting!