Error : Index in position 1 is invalid
Mostrar comentarios más antiguos
I am trying to keep my index(s) row and/or col positive so I added some if statments to reinitiat row - 1 and col - 1 to equatl 1. Also vise versa for row+1 = 10 and col+1=10 to make then just equal Nx/Nx. I thought I coded it correctly but I keep getting an error and cannot think of anything else.
Nx = 9;
Ny = 9;
domain=zeros(Nx,Ny);
cons1=epsilon_0/(epsilon_0+epsilon_r);
cons2=epsilon_r/(epsilon_0+epsilon_r);
for row = 1:Ny
for col = 1:Nx
if row > Ny
row = row - 1;
end
if row < 1
row = row+1;
end
if col > Nx
col = col-1;
end
if col < 1
col = col-1;
end
v1 = domain(row, col+1);
v2 = domain(row-1, col);
v3 = domain(row, col-1);
v4 = domain(row+1, col);
if row == (1/3)*(Ny+1) || row ==(2\3)*(Ny)
domain(row,col) = cons1*v1+cons2*v3+(1/4)*(v2+v4);
elseif row == 1
domain(0, col)=(1/4)*(v1+v3+2*v4);
elseif col == 1
domain(0, col)=(1/4)*(2*v1+v2+v4);
else
domain(row,col) = (1/4)*(v1+v2+v3+v4)
end
end
end
I keep getting this error:
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in HW6dif (line 64)
v2 = domain(row-1, col);
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!