필터 지우기
필터 지우기

Index must be a positive integer or logical.

조회 수: 3 (최근 30일)
Shashank
Shashank 2012년 10월 27일
I am getting the following error while running the code:
Attempted to access R1_rk4(17501); index must be a positive integer or logical.
Here's a part of my code where the problem lies:
ie1 = 1 + 0.000035/h1;
R1_te = R1_rk4(ie1);
e_R1 = abs(R1_te - R3_te);
Btw, R1_rk4 is a vector, not a matrix. h1 is a constant (time step in the problem). I am trying to access a specific element of the vector R1_rk4 whose size is (1 x 80000).
Any help in removing the error would be much appreciated.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 27일
편집: Azzi Abdelmalek 2012년 10월 27일
The problem is in
R1_te = R1_rk4(ie1);
what is the value of ie1
ie1 must be a positive integer or logical.
  댓글 수: 1
Shashank
Shashank 2012년 10월 27일
Thanks Azzi. I found out the mistake. The term 0.000035/h1 although turns out to be 17501 when calculating analytically but numerically it will not be an exact integer and that's enough for the indexing routine to complain about it being non-integral.

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

추가 답변 (2개)

Image Analyst
Image Analyst 2012년 10월 27일
What's the value of ie1? Is it an integer? Maybe you want
integerIndex = max([1 round(ie1)]);
R1_te = R1_rk4(integerIndex);
  댓글 수: 1
Shashank
Shashank 2012년 10월 27일
Thanks Image Analyst. I basically need to round off the index to the next possible integer value.

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


Walter Roberson
Walter Roberson 2012년 10월 27일
  댓글 수: 1
Shashank
Shashank 2012년 10월 27일
Thanks for the link, Walter. I'll check the wiki section before asking a question here.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by