I am using a for loop to calculate the electric potential on a subset of the xy-plane (a square grid). Here is the code:
L=2;
for i=1:L
for j=1:L
for k=1:L
V(i,j,k)= -10;
end
end
end
where L is the length of the subset of the xy-plane. The difficulty I am having, however, is that I want the z component of the electric potential to be zero, I just want to the region in the xy-plane to be nonzero. The reason why I am using three dimensions is because I am going to eventually introduce an object, which is at a different electric potential relative to the plane, that is above the plane.
What I tried was taking a simple two dimensional matrix:
a =
1 1 1
1 1 1
and tried replacing the ones in the second column with zeros, which I did by typing a(:,2)=0, and matlab gave me
a =
1 0 1
1 0 1
I then tried to generalize this to a 3 dimensional matrix, but ran into some difficulty. Could someone help me?
(x,y,z)
has a z-component. – DanielM(1,1,1)
is the zero point. Indexing starts at 1, that makes it a bit tricky. – Daniel