- First try calling your for-loop in reverse order to see if that reproduces it. If so, it'll be much easier to debug.
- Next, call ga, but different output values. For instance
Error using MATLAB GA - [left and right sides have a different number of elements]
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
var1 = (linspace(100, 400, 10));
var2 = (linspace(2, 7, 10));
for i=1:length(var2)
for j=1:length(var1)
objFun = @(x) my_objFun(var1(j),var2(i));
constraintFun = @(x) my_constraintFun(var1(j),var2(i));
try
[x,fval,exitflag,output]= ga(objFun,nvars,A,b,Aeq,beq,lb,ub,constraintFun,IntCon,options);
catch e
fprintf(1,'[ERROR] - The identifier was:\n%s\n',e.identifier);
fprintf(1,'[ERROR] - There was an error! The message was:\n%s\n',e.message);
end
end
end
The GA function is called repetitive times inside a loop. It sometimes runs successfully, other times it throws ERROR 1 and in a few other occasions it throws ERROR 2.
- ERROR 1
[ERROR] - The identifier was:
MATLAB:matrix:singleSubscriptNumelMismatch
[ERROR] - There was an error! The message was:
Unable to perform assignment because the left and right sides have a different number of elements.
- ERROR 2
[ERROR] - The identifier was:
MATLAB:griddedInterpolant:NonMonotonicCompVecsErrId
[ERROR] - There was an error! The message was:
Sample points must be unique and sorted in ascending order.
Any idea what that could be?
I'm using try and catches all over my my_objFun and my_constraintFun to make sure this error is not coming from there.
4 Kommentare
Antworten (1)
Alan Weiss
am 8 Aug. 2021
I do not understand this line:
objFun = @(x) my_objFun(var1(j),var2(i));
Where does the variable x enter objFun? I think that is your main problem. Try calling
objFun(x0)
for some x0 that is a row vector with nvars elements. It probably will not return what you hope it returns.
Alan Weiss
MATLAB mathematical toolbox documentation
1 Kommentar
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!