필터 지우기
필터 지우기

Matlab: Error in copied and renamed function

조회 수: 3 (최근 30일)
Sepp
Sepp 2016년 6월 19일
답변: Star Strider 2016년 6월 19일
Hello
I'm using the ga() function of Matlab for parameter optimization in the following way:
options = gaoptimset('CrossoverFraction',0.8,'FitnessScalingFcn',@fitscalingrank,'TolFun',1e-6,...
'Generations',50,'PopulationSize',20,'EliteCount',2);
minfn = @(z)myLossFunction(z);
[x,fval,~,output] = ga(minfn,8,[],[],[],[],LB,UB,[],1,options);
LB and UB are just matrices with the lower and upper bound for the variables.
The above code works very well. Now, I have made a local copy of the ga() function and named it ga2() because I want to make some modification to it. Now I'm calling it in the following way:
[x,fval,~,output] = ga2(minfn,8,[],[],[],[],LB,UB,[],1,options);
I did not do any modifications yet, I just renamed it to ga2().
Now I'm getting the following error at line 295 of the call gaminlpvalidateoptions(options); of ga2():
Undefined function 'gaminlpvalidateoptions' for input arguments of type 'struct'.
If I comment it out, I'm getting a new error on line 328 saying:
Undefined function 'gacommon' for input arguments of type 'function_handle'.
Why is this and how can I get rid off? I have just copied and renamed the ga() function.

채택된 답변

Star Strider
Star Strider 2016년 6월 19일
You took it out of its natural environment (the toolbox directory where the original version of it used to live) and now it can’t find the functions it depends on, because it doesn’t know where to look for them.
It’s probably not good to modify MATLAB code anyway. Genetic algorithm functions aren’t difficult to write de novo, but aren’t as efficient or robust as the Global Optimization Toolbox code for them.
If the original function works with your code, just go with it!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by