matlab strange behaviour of function sum()

后端 未结 1 1299
半阙折子戏
半阙折子戏 2021-01-26 08:41

Any idea why Matlab could behave like this?

>> sum([0 0 0])
Subscript indices must either be real positive integers or logicals.

>> sum([1 1 1])

an         


        
1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-26 09:11

    you've overridden the function sum and now it is considered a local variable

     sum = s(1, 1);
    

    thus you are hiding sum as function.

    Change the variable name and do

     clear sum
    

    .

    0 讨论(0)
提交回复
热议问题