how can i fix subscript indices must be either real positive integers or logicals
5 vues (au cours des 30 derniers jours)
metasebia dabi le 23 Juin 2021
I am new to matlab and i am tring to do multi objective optimization using gamultiobj , i have multi functions but when i try to run each function it says "Not enough input argument " plus when i try to run the main fun it says subscript indices must be either real positive integer or logicals" i have attached all of my functions!
Walter Roberson le 23 Juin 2021
At a location approximately half way through the third line, you have
(x(60^3*(x(1) - x(2)))/6
You might possibly have intended something like (x(6)^3*(x(1)-x(2)))/6 . But watch out for just replacing the 0 with a ) -- you would have had to add an extra ) to get the ) to balance and there is no telling where you added it.
You appear to have used some kind of code generation to generate your code from a symbolic expression. I can tell that you did not use matlabFunction() just by itself -- but it is possible that you used matlabFunction() and then hand-editted pieces together.
I recommend that you go back to the code generation and tell it to optimize. Not so much that you want the optimization (though that would not hurt), but rather that you want the expressions to be split into multiple lines for readability.
And when you create the symbolic expressions that you are going to do code generation for, you should wrap every numeric constant with a sym() call, except that you can leave powers alone. Seeing numbers such as
(19515681011313314790985107421875*x(5))/73786976294838206464 in your code makes it clear that you just let it convert floating point constants to whatever was most convenient... that divisor is 2^66 exactly.
So for example,
c = 2.99792458e8
arfreq = 0.000000488;
obj = arfreq/c*t
you would instead do something like
Q = @(v) sym(v);
c = Q(299792458);
arfreq = Q(488)/sym(10)^9; %avoid floating point
obj = arfreq/c*t
In this case the pure numeric constants would lead to generating 2304514843640387*t/4722366482869645213696 but the more careful constants would lead to 61*t/37474057250000000 . Which is still a bit "funny money", magic constants with no obvious meaning to look at them, but they would be a lot more comprehendable, without the problems like 0.000000488 being converted to 2304514843640387/4722366482869645213696