index must be a positive integer or logical
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
for i=1:1:7
P(1)=1000;
P(7)=500;
f(i)=P(i-1)^2-P(i-1)*P(i)-P(i)^2+P(i)*P(i+1);
disp f(i)
end
All my declared variables here are integers. How do I resolve this error?
댓글 수: 0
답변 (1개)
Azzi Abdelmalek
2016년 3월 22일
편집: Azzi Abdelmalek
2016년 3월 22일
0 개 추천
when you write p(i), make sure that i is a positive integer, not equal to 0. in your case, you have p(i-1), if i is equal to 1, then i-1 will be 0, which is not allowed by Matlab as an index
댓글 수: 1
Amey
2016년 3월 22일
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!