MATLAB: Why showing ‘Array indices must be positive integers or logical values.’

array indices must be positive integers or logical values.

m2 = zeros(N,1); %2Matrix of second moment matrix
m2_pul = zeros(N,1); %x(n)x(n+t)Matrix frame
fs = 50;
for t1 = (0:N-1)/fs
n = 1:N;
m2_pul(n) = sig(n) .* sig(n+t1); %x(n)x(n+t)
m2(t1+1) = mean(m2_pul); %E[x(n)x(n+t)]
m2_pul = zeros(N,1);
end
Array indices must be positive integers or logical values.
Error in bispectrum (line 12)
m2_pul(n) = sig(n) .* sig(n+t1); %x(n)x(n+t)
Error in bi_estimation (line 102)
[c3_w]=bispectrum(sig,sig2,N);

Best Answer

m2 = zeros(N,1); %2Matrix of second moment matrix
m2_pul = zeros(N,1); %x(n)x(n+t)Matrix frame
fs = 50;
f = (0:N-1)/fs ;
for t1 = 1:length(f)
n = 1:N;
m2_pul(n) = sig(n) .* sig(n+t1); %x(n)x(n+t)
m2(t1+1) = mean(m2_pul); %E[x(n)x(n+t)]
m2_pul = zeros(N,1);
end
The indices of array in MATLAB cannot be zero, negative and fractions. When you take:
t1 = (0:N-1)/fs
t1 has fractions, you cannot use them as indices; so error.
Related Question