Warning: Integer operands are required for colon operator when used as index.
18 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
DGM
le 9 Avr 2021
You need integers to do indexing operations.
plot(f,Ak(1:floor((length(V2)+1)/2))); grid on
0 commentaires
Walter Roberson
le 9 Avr 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.
0 commentaires
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!