필터 지우기
필터 지우기

How to use the SUM() function..?

조회 수: 4 (최근 30일)
paul
paul 2022년 10월 5일
이동: Steven Lord 2022년 10월 5일
Hello,
I must be doing something very stupid here, as I can't get the sum() function to work at all;
X = [0 0.5 1 1.5 2 2.5]
sum(X(1,:))
From what I've read, this should sum all the element of row 1 of the matrix X and return a numerical result, but when I try it, I get the error:
Array indices must be positive integers or logical values.
Can anybody tell me what I'm doing wrong, please?
Thanks,
Paul

채택된 답변

Bruno Luong
Bruno Luong 2022년 10월 5일
You overshadow sum function
make sure to run
clear sum
before runing your code
  댓글 수: 2
paul
paul 2022년 10월 5일
이동: Steven Lord 2022년 10월 5일
...As is so often the way, I almost instantly found the problem after bashing my head against it and then posting my question...
I cleared all my workspace variables and suddenly sum(0 started working, so there must have been something in there which was stopping sum() from working...
Thanks to anybody who was thinking about this for me,
Paul
paul
paul 2022년 10월 5일
이동: Steven Lord 2022년 10월 5일
Thanks very much :)

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

추가 답변 (1개)

Torsten
Torsten 2022년 10월 5일
Did you create a MATLAB function with name sum.m ? If yes, rename it.

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by