Warning: Integer operands are required for colon operator when used as index.

41 visualizaciones (últimos 30 días)
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]);

Respuestas (2)

DGM
DGM el 9 de Abr. de 2021
You need integers to do indexing operations.
plot(f,Ak(1:floor((length(V2)+1)/2))); grid on

Walter Roberson
Walter Roberson el 9 de Abr. de 2021
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.

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by