How can I solve the following error?
2 次查看(过去 30 天)
显示 更早的评论
For an arbitrary matrix, I want to sum the entries of each row of it.
I use the command sum(A,2) for the square matrix A. But I encounter the following error
"Index in position 1 is invalid. Array indices must be positive inteders or logical values"
0 个评论
回答(2 个)
Star Strider
2022-7-6
Somewhere you have a variable named ‘sum’ and this is throwing the error.
The solution is to re-name the variable to something else that makes sense in the context of the code and does not overshadow any MATLAB function names.
0 个评论
Fangjun Jiang
2022-7-6
Most likely, you have a variable called "sum". Clear it first and then run your code
clear sum;
A=magic(5);
sum(A,2)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!