Can someone help me solve this problem (Array indices must be positive integers or logical values)
조회 수: 1 (최근 30일)
이전 댓글 표시
I tried to get the answer from this equation: sum(abs(diff(CPap)))*freq/length(CPap)
I assumed I need to tell matlab what CPap, freq and length represent right?
So I typed in CPap = 0.3, freq = 100 an length = 10
But when i hit enter, this sentence showed, can someone tell me what am i doing wrong here?
Many thanks!!!
댓글 수: 0
답변 (1개)
Arvind Sathyanarayanan
2019년 3월 28일
The issue is with length(CPap). You're trying to divide sum(abs(diff(CPap)))*freq by length(0.3), in your case length is not an array. If it was an array, then indices must be positive integers
댓글 수: 7
Arvind Sathyanarayanan
2019년 3월 28일
편집: Arvind Sathyanarayanan
2019년 3월 28일
Let's say x is an array.
x = [9 7 5 3 2]
x(1) = 9, x(2) = 7, ... , x(5) = 2
What you're trying to do is x(Cpap), which is equivalent to x(0.3). 0.3 is not a valid array index. Array indexes can only be positive and integer values.
Index exceeds the number of array elements (1)
This happens when you call for x(6) because, x(6) is not defined.
Also, am I differenciating a constant number here? Casue no matter what I do I will get 0 at the end?
Yes, diffrentiating on a constant will return zero but, the function diff() has other uses as well. I encourage you to read the documentation.
It'll be helpful if you explain what you're trying to achieve. Use to latex editor to type in the equation or post a screenshot of the equation you're trying to implement.
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!