# MATLAB: Index must be a positive integer or logical

sequence

Hi in order for a student work i need to calculate a sequence for a velocity.
This velocity depends on x and y, those 2 variables are valued from x 0..1 and y -1..1.
But i cant calculate this for these values because of this error.
My code looks like this:
M=10;K=10;A=zeros(M,K);for x=0:0.1:1      for y=-1:0.2:1              for n=1:20                             %Berechnung eines Gliedes              A(x,y)=((-1^n)/( ((2*n-1)* pi)/2*0.83)^3 * cos(((((2*n-1)*...              pi)/2*0.83))*y)*((exp(((((2*n-1)* pi)/2*0.83))*(x-1))*exp(((-((2*n-1)*...              pi)/2*0.83))*(x+1)))/1+exp(-2*((2*n-1)* pi)/2*0.83)));              end;      end;end;
Maybe someone is able to help me. And pls use simple explanations because im not working long with matlab 😀

x=0:0.1:1;y=-1:0.2:1;n=1:20;[X,Y] = meshgrid(x, y);Afcn = @(x,y,n) ((-1.^n)./(((2.*n-1).*pi)./2.*0.83).^3 .* cos(((((2.*n-1).*...              pi)./2.*0.83)).*y).*((exp(((((2.*n-1).*pi)./2.*0.83)).*(x-1)).*exp(((-((2.*n-1).*...              pi)./2.*0.83)).*(x+1)))./1+exp(-2*((2.*n-1).*pi)./2.*0.83)));A = [];for k1 = 1:length(n)    A(:,:,k1) = Afcn(X,Y,n(k1));endfigure(1)surf(A(:,:,20))hold onfor k1 = 2:length(n)    surf(A(:,:,k1)+n(k1))endhold offxlabel('X')ylabel('Y')zlabel('n')