필터 지우기
필터 지우기

Why do I get a warning about 'Integer Operands Are Required for Colon Operator When Used as Index' ?

조회 수: 501 (최근 30일)
Why do I get the following error message:
ERROR: Warning: Integer operands are required for colon operator when used as index.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2021년 10월 11일
편집: MathWorks Support Team 2021년 11월 17일
Explanation:
You have used a noninteger value as one of the parameters (starting value, increment, or stopping value) for the colon (:) operator when using it to create a vector of indices to reference into a function.
Common causes:
You performed computations to obtain the starting or stopping values for the indexing but the result of those computations was not exactly an integer.
Solution:
Modify the index computations using the FIX, FLOOR, CEIL, or ROUND functions to ensure that the indices are integers. You can test if a variable contains an integer by comparing the variable to the output of the ROUND function operating on that variable when MATLAB is in debug mode on the line containing the variable.
https://www.mathworks.com/help/matlab/ref/fix.html
https://www.mathworks.com/help/matlab/ref/floor.html
https://www.mathworks.com/help/matlab/ref/ceil.html
https://www.mathworks.com/help/matlab/ref/round.html
Example demonstrating this error:
IntegerOperandsRequired.m
  댓글 수: 2
bethel o
bethel o 2023년 4월 4일
But how can the problem be located as the warning does not include the offending line?
Steven Lord
Steven Lord 2023년 4월 4일
The "Error Breakpoints" category of breakpoints listed on this documentation page does not simply allow you to enter debug mode when an error occurs. Also included in that category are the ability to enter debug mode when a warning is issued or when either Inf or NaN are created in your code. So set an error breakpoint to stop when a warning is issued, run your code, and see where MATLAB enters debug mode.

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

추가 답변 (0개)

카테고리

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