Matlab: Error in copied and renamed function

1 visualización (últimos 30 días)
Sepp
Sepp el 19 de Jun. de 2016
Respondida: Star Strider el 19 de Jun. de 2016
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.

Respuesta aceptada

Star Strider
Star Strider el 19 de Jun. de 2016
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!

Más respuestas (0)

Categorías

Más información sobre Genetic Algorithm en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by