Warning: Integer operands are required for colon operator when used as index.
17 次查看(过去 30 天)
显示 更早的评论
Ak=2*abs(fft(V2))/length(V2);Ak(1)=Ak(1)/2;
f=[0:1:(length(V2)-1)/2]*Fs/length(V2);
figure();
plot(f,Ak(1:(length(V2)+1)/2));grid on %(This line is causing the problem)
title('Spectrum for tone');
ylabel('Amplitude');
xlabel('frequency (Hz)');
axis([500 2000 0 1]);
0 个评论
回答(2 个)
DGM
2021-4-9
You need integers to do indexing operations.
plot(f,Ak(1:floor((length(V2)+1)/2))); grid on
0 个评论
Walter Roberson
2021-4-9
If length(V2) is even, then length(V2)-1 is odd, and length(V2)-1)/2 would not be an integer when you do the 0:1: operation. Likewise, if length(V2) is even, then length(V2)+1 is odd and (length(V2)+1)/2 would not be an integer when you do the 1: operation.
0 个评论
另请参阅
类别
在 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!