필터 지우기
필터 지우기

"Warning: Integer operands are required for colon operator when used as index" in fft

조회 수: 2 (최근 30일)
Hello everyone, I tried to write a script in order to perform a fft of an accelerometric signal. When I run the code the warning in object appears. Below the faulty code line (second line):
xdft1=fft(x1-mean(x1))/N1;
xdft1=xdft1(1:N1/2+1);
where x1 is the accelerometric signal and N1=length(x1). I deem the problem is in the operation N1/2 and I think I have to use the function "floor". Can you help me? Thank you very much!

채택된 답변

Walter Roberson
Walter Roberson 2016년 10월 11일
N1 is odd, so N1/2 is a fraction. Add 1 to that and it is still a fraction. You are then trying to index from 1 to that fraction. That will give you a warning.
You need to either prevent N1 from being odd, or else you need to use floor() or fix() or round() on the N1/2 so that it is no longer a fraction
  댓글 수: 1
Guglielmo Giambartolomei
Guglielmo Giambartolomei 2016년 10월 11일
Thank you Walter, I changed the code line with xdft1=xdft1(1:floor(N1/2)+1) and the warning disappeared. Now I have to understand better what the code do.

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

추가 답변 (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