how can i fix subscript indices must be either real positive integers or logicals

조회 수: 3(최근 30일)
metasebia dabi
metasebia dabi 2021년 6월 23일
댓글: metasebia dabi 2021년 8월 6일
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!
  댓글 수: 5
Walter Roberson
Walter Roberson 2021년 6월 25일
Then you are using R2015b or earlier, and should have mentioned that. You should switch to using fprintf()
fprintf('Total Function Count: %d\n', gaoutput1.funccount);
When someone says that they are new to MATLAB, we do not expect them to be using a version that is 5 years old.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2021년 6월 23일
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,
syms t
c = 2.99792458e8
arfreq = 0.000000488;
obj = arfreq/c*t
you would instead do something like
syms t
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
  댓글 수: 45
metasebia dabi
metasebia dabi 2021년 8월 6일
I insert one of the final result of optimized solutions from my previous code , which are x1,x2,x3,x4,x5,x6,x7 and insert this results in the design code , the previous code is formulated using this design code so after inserting this results I run the code and calculate the result of safety factor Mn/Mr but in the optimization this result is fgal2 and the result is 11 but the out put of the original code using the optimized cross sections is 3,my question is why does it have this difference in results , is it b/c I use -f2 to maximize?

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by