From: matlab_learner on
Hello
I am using Matlab. I have a 2D array r(i,j), which I am performing
iteration on. At the end of each iteration level, k, I get the value
of r(i,j).

I would like to store the value of r(i,j) at any iteration level k,
but I don't know how to program it. I hope someone can advice. Here is
my code so far. Thank you.
b = 0; %intialize b;
for j = 1:21
for i = 1:21
b(i,j) = (2 * (2 - (x(i))^2 - (y(j))^2)); %b is size 21X21
end
end

for k =1:100 % k is the number of iteration.
r(i,j)= 0; %initialize residual array r
while j < 20
while i < 20
phi(1,1)=0;
phi(20,20) = 0;
phi(20,1) = 0;
phi(1,20) = 0;
phi(i,j) = 0.25 * (phi(i-1,j) + phi(i+1,j) + phi(i,j-1) +
phi(i,j+1)) - 0.25 * b(i,j);
i = i + 1;
end
j = j + 1;
end
while j<20
while i <20
r(i,j) = max( abs(b(i,j) - (1/(delta)^2) * ( phi(i-1,j) -
4 * phi(i,j) + phi(i+1,j) + phi(i,j+1) + phi(i,j-1))),r);
i = i+1;
end
j = j + 1;
end

pj_1_residual(k) = r;
end
bcos r is r(i,j) and my pj_1_residual is a 1 D as yet, how can I write
pj_1_residual such that it would be storing the r value at each k, so
if i wanted to i could do an if-statement such as
if k==3
pj_1_3 = r
end

or something. thans.