MATLAB: Array indices must be positive integers or logical values

errorindex starting at 0needs to start with 1

H = 0;
M = length(h);
for k=0:M-1
H = H + (h(k) * exp(-1i*2*pi*fd));
end
%fd and h come from a function call

Best Answer

The problem:
for k=0:M-1
The solution:
for k=1:M
In MATLAB, subscript indices begin at 1, not 0, and are defined as integers greater than 0.
It is more efficient to do this without the loop:
H = cumsum(h* exp(-1i*2*pi*fd));
or simply:
H = sum(h* exp(-1i*2*pi*fd));
Related Question