I'm trying to calculate harmonic average in a Matlab function.
When I wrote the code below, I noticed Matlab doesn't seem to understand (i) as a counter variable.
Please advise why is this and how to resolve it. Thanking you in advance.
In main code I have:
kx = [10,20,30];
ky = [70,80,90];
In a function, I have:
function [harmonic_average] = harmonic_perm(kx,ky)
kxharmforward(i) = 2*(kx(i)*kx(i+1))/(kx(i)+kx(i+1));
kxharmbackward(i) = 2*(kx(i)*kx(i-1))/(kx(i)+kx(i-1));
kyharmupward(i) = 2*(ky(i)*ky(i+1))/(ky(i)+ky(i+1));
kyharmdownward(i) = 2*(ky(i)*ky(i-1))/(ky(i)+ky(i-1));
This is the error I get when I run the code
Array indices must be positive integers or logical values.
Error in harmonic_perm (line 3)
harmonic_average(i) = 2*(kx(i)*kx(i+1))/(kx(i)+kx(i+1));
Error in Main_Code (line 139)