ERROR: Index in position 1 is invalid. Array indices must be positive integers or logical values.
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi, I'm getting this error when I index into an image using roi_5, the contents of which are shown below. I'm assuming that the issue is a result of the '10e-09*' at the start. Does anyone know how to deal with this? Or is something else likely to be causing the error?
I've tried to divide by the 10e-09 factor but this hasn't fixed anything.
roi_5 is defined as;
roi_5 = R1rho(22:30, 28:36);
The contents of roi_5:
roi_5 =
1.0e-09 *
0.0313 0.0342 0.0347 0.0307 0.0337 0.0318 0.0355 0.0381 0.0394
0.0329 0.0345 0.0411 0.0412 0.0458 0.0432 0.0456 0.0458 0.0405
0.0383 0.0473 0.0453 0.0393 0.0486 0.0445 0.0455 0.0570 0.0496
0.0415 0.0499 0.0559 0.0541 0.0656 0.0597 0.0627 0.0692 0.0549
0.0457 0.0611 0.0572 0.0508 0.0676 0.0587 0.0636 0.0794 0.0665
0.0491 0.0581 0.0687 0.0650 0.0815 0.0725 0.0811 0.0872 0.0685
0.0638 0.0678 0.0741 0.0655 0.0787 0.0749 0.0777 0.0886 0.0858
댓글 수: 0
답변 (1개)
KSSV
2021년 2월 5일
The error is not due to 10e-09. In the present, you have not shown us the complete code, so we cannot help you exactly. But this error occurs when you try to use indices as negative or zero. Rememebr, in MATLAB the indices are always positive integers and logicals; if any other is used, you will get an error.
Example:
A = rand(10,1) ;
A(1) % no error
A(-1) % error, index cannot be negative
A(0) % error, index cannot be zero
A(0.5) % erorr, index cannot be a fraction
So, in your code you have to see where you got the error, go to that line and check the index value.
댓글 수: 2
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!