Index Exceeds Matrix Dimension error

Hi,
I keep betting the above error for the code below, It seems to be for the line g = x(1*44100+(1:44100));
function [x, freq, t] = tones(f,a)
freq_oscillation =4.5;
amp_oscillation = 0.04;
Fs = 44100; len = 11;
t= [0:len*Fs]./Fs;
Phi(1) = 0;
for i = 2:size(t, 2)
Phi(i) = cos(Phi(i-1)+(2.*pi.*t(i).*freq_oscillation));
end
%for i = 1 : 11
gamma = 1+(Phi(i).*amp_oscillation);
for s = 1 : length(a);
x =+ (3.*a(s))*(cos(gamma.*f*2*pi));
end
sound(x,Fs);
plot(t,x);
xlabel('Time');
ylabel('FM');
g = x(1*44100+(1:44100));
NFFT = 2^nextpow2(length(g));
h = fft(g, NFFT)/length(g);
fre = Fs/2*linspace(0,1,((NFFT/2)+1));
subplot(2,1,2)
plot(fre,2*abs(h(1:((NFFT/2)+1))))
xlabel('Hz');
ylabel('Amplitude');
figure;
[S,F,T,P] = spectrogram(x,hamming(1024),512,1024,44100);
surf(T,F,10*log10(P),'edgecolor','none');
axis([0 len 0 5000]);
xlabel('Time (Seconds)');
ylabel('Hz');
end
Maybe I have been starting at it for too long and cant seem to realise what is wrong. Can anyone help?
Thanks,
Shelly

1 个评论

Please show us how to you call this function: The size of f is important.

回答(1 个)

Jan
Jan 2013-4-16
编辑:Jan 2013-4-16
Such problems can be investigated using the debugger. Set a brakpoint in the first line and check, how the value of x is created. Then it will get clear, why x does not have 88200 elements.
Please note that it is unlikely, that you really get this error message, because the code will not even run:
x =+ (3.*a(s))*(cos(gamma.*f*2*pi))
There is no =+ operator in Matlab - or are you using the beta-version of 2014a?

此问题已关闭。

提问:

2013-4-16

关闭:

2021-8-20

Community Treasure Hunt

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

Start Hunting!

Translated by