Index in position 1 is invalid. Array indices must be positive integers or logical values.
조회 수: 4 (최근 30일)
이전 댓글 표시
I have :
c(i,2) = 272.0000
c(i,1) = 42.0000
and L(272.0000,42.0000) gives 2
but when I do
L( c(i,2), c(i,1) )
(L is a 697x103 double)
I got
Index in position 1 is invalid. Array indices must be positive integers or logical values.
댓글 수: 0
채택된 답변
Dyuman Joshi
2023년 2월 10일
편집: Dyuman Joshi
2023년 2월 10일
The error occurs because your data is not exactly an integer even though it might look like it.
%Data displayed in the default format i.e. short format
y = 1.0000123
Type
format long
in your code and see the value of the the elements.
y
Use round(), floor() or ceil() according to what you want to do.
L( round(c(i,2)), round(c(i,1)))
추가 답변 (1개)
Mathieu NOE
2023년 2월 10일
hello
depending of your format, the command window will display more or less decimals
I suspect
c(i,2) = 272.0000...............123
c(i,1) = 42.0000...............789
are not 100% integer so you have to round them to the nearest integer to make your code work
L( round(c(i,2)), round(c(i,1)) ) should now display the correct value
참고 항목
카테고리
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!