Undefined operator '+' for input arguments of type 'table'

조회 수: 1 (최근 30일)
Marco Rozzi
Marco Rozzi 2019년 9월 26일
편집: Stephen23 2019년 9월 26일
Hello to everybody,
I have a problem with a particular algorithm that performs a multi-objective optimization.
When I try to select a certain number of columns using two parameters in the algorithm this error appears: "Undefined operator '+' for input arguments of type 'table'", but when I try to do the same thing with 2 normal passages on the command window it works.
Could someone help me?
There are some pictures to understand what I meana.jpg
b.jpg
  댓글 수: 2
Stephen23
Stephen23 2019년 9월 26일
편집: Stephen23 2019년 9월 26일
The curse of global variables!
Global variables make it possible for data to be changed at any time by any function/class, which is why it is recommended to avoid using them. Most likely you could avoid this bug by writing better code without reyling on anti-pattern global variables.
etc.
Rather than global variables I strongly recommend either using nested functions or parameterizing your function/s., as appropriate for your algorithm.
Nothing in your code indicates why those variables defined in the base workspace should be the same as those global variables.
Marco Rozzi
Marco Rozzi 2019년 9월 26일
I thought that was an elegant way use this kind of variable.
I have changed my script defining the variables for each function and it seems to work.
Thank you, I was going crazy

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

답변 (1개)

Sebastian Körner
Sebastian Körner 2019년 9월 26일
try this:
i=V+M+1;
a= table2array(population(:,i))
if all(a(:)==0)
...
end

카테고리

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

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by