I am trying to change 2 different rows in my table according to one random variable each time, For example I want if a random number>0.5 then to change one row with the value in it +1 and the other row with its value -1, otherwise do nothing. I tried the following code but I am confused, Can anyone please help me?
InitialMatrix[3, 3, 3, 3] +
MapAt[f, MapAt[g, Table[0, {3}, {3}, {3}, {3}],
Flatten[Table[{i, j, 1, k}, {i, 3}, {j, 3}, {k, 3}], 2]],
Flatten[Table[{i, j, 2, k}, {i, 3}, {j, 3}, {k, 3}], 2]] // TableForm
f[x_] := If[RandomReal[] > 0.5, g[x] = If[x > 0, x - 1, x];
If[g[x] > 0, x + 1, x], x]
Thank you very much!!
Edit: Changed requirements
I have a four dimensional table and I want to change the values in it with respect to each other.
My table is
InitialMatrix[x_, y_, age_, disease_] :=
ReplacePart[ Table[Floor[Divide[dogpopulation/cellsno, 9]],
{x}, {y}, {age}, {disease}], {{_, _, 1, _} -> 0, {_, _, 3, _} -> 6}];
I am trying to change the first 2 rows in each subtmatrix according to one random variable each time.
For example I want if a random number>0.4 then to change the first element in the first row with its value +1 and the first element of the second row with its value minus 1 otherwise leave the value as it is.
I want to check every element in the first row with a different random number and if the condition is true then to change both 1 and second row. Can I do something like that?
See Question&Answers more detail:
os